Skip to content

Commit

Permalink
feat: DeepEqual 유틸 타입 추가 (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 authored Jan 10, 2025
1 parent 317f639 commit 2ecdfd1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-badgers-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-kit/types': minor
---

feat(types): DeeoEqual 유틸 타입 추가 - @ssi02014
26 changes: 26 additions & 0 deletions packages/types/src/DeepPartial/DeepEqual.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, it, expectTypeOf } from 'vitest';
import { DeepPartial } from '.';

describe('DeepPartial', () => {
interface User {
name: string;
age: string;
address: {
street: string;
city: string;
};
}

it('DeepPartial 타입은 중첩된 객체의 모든 속성을 선택적으로 만들어줍니다.', () => {
const user: DeepPartial<User> = {
name: 'John',
age: '20',
};

expectTypeOf(user).toEqualTypeOf<{
name?: string;
age?: string;
address?: { street?: string; city?: string };
}>();
});
});
28 changes: 28 additions & 0 deletions packages/types/src/DeepPartial/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @description 객체의 모든 속성을 선택적(optional)으로 만드는 타입
* 중첩된 객체의 경우에도 재귀적으로 모든 속성을 선택적으로 변환합니다.
*
* @template {Record<PropertyKey, any>} T - 변환할 객체 타입
* @example
* interface User {
* name: string;
* age: number;
* address: {
* street: string;
* city: string;
* };
* }
*
* type PartialUser = DeepPartial<User>;
* // {
* // name?: string;
* // age?: number;
* // address?: {
* // street?: string;
* // city?: string;
* // };
* // }
*/
export type DeepPartial<T extends Record<PropertyKey, any>> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './Arrayable';
export * from './DeepPartial';
export * from './DistributiveOmit';
export * from './ExcludeNullish';
export * from './ExtractMapType';
Expand Down

0 comments on commit 2ecdfd1

Please sign in to comment.