-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@modern-kit/types': minor | ||
--- | ||
|
||
feat(types): DeeoEqual 유틸 타입 추가 - @ssi02014 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}>(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters