1. Mapped Types ์ ๋ฆฌ
Partial: ํด๋์ค์ ํ๋กํผํฐ ์ ์๋ฅผ ๋ชจ๋ optional๋ก ๋ง๋ ๋คPick: ํน์ ํ๋กํผํฐ๋ง ๊ณจ๋ผ ์ฌ์ฉ ํ ์ ์๋ค. (Omit์ ๋ฐ๋)Omit: ํน์ ํ๋กํผํฐ๋ง ์๋ต ํ ์ ์๋ค. (Pick์ ๋ฐ๋)Intersection: ๋ ํ์ ์ ํ๋กํผํฐ๋ฅผ ๋ชจ๋ ๋ชจ์์ ์ฌ์ฉ ํ ์ ์๋คComposition: Mapped Types๋ฅผ ๋ค์ํ๊ฒ ์กฐํฉํด์ ์ค์ฒฉ ์ ์ฉ ๊ฐ๋ฅํ๋ค
2. Partial
1export class CreateUserDto {2@IsString()3readonly name: string45@IsEmail()6readonly email: string78@IsString()9readonly password: string10}
1export class UpdateUserDto extends PartialType(CreateUserDto) {}2/*3{4name?: string;5email?: string;6password?: string;7}8*/
3. Pick
1export class CreateUserDto {2@IsString()3readonly name: string45@IsEmail()6readonly email: string78@IsString()9readonly password: string10}
1export class LoginUserDto extends PickType(CreateUserDto, ['email', 'password'] as const) {}2/*3{4email: string;5password: string;6}7*/
4. Omit
1export class CreateUserDto {2@IsString()3readonly name: string45@IsEmail()6readonly email: string78@IsString()9readonly password: string10}
1export class PublicUserDto extends OmitType(CreateUserDto, ['password'] as const) {}2/*3{4name: string;5email: string;6}7*/
5. Intersection
1export class UserDetailDto {2@IsString()3readonly name: string45@IsEmail()6readonly email: string7}89export class AddressDto {10@IsString()11readonly street: string1213@IsString()14readonly city: string1516@IsString()17readonly country: string18}
1export class UserWithAddressDto extends IntersectionType(UserDetailDto, AddressDto) {}2/*3{4name: string;5email: string;6street: string;7city: string;8country: string;9}10*/
6. Composition
1export class UpdateCatDto extends PartialType(2OmitType(CreateCatDto, ['name'] as const), //3) {}