Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DeepPartial 유틸 타입 추가 #667

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading