Frontend2025년 3월 1일1분 읽기

TypeScript 5.4 실전 활용 — Utility Types 마스터

YS
YoungSam
조회 966

필수 유틸리티 타입

// Partial + Required 조합
type UpdateUser = Partial<User> & Required<Pick<User, "id">>;

// Record로 맵 타입 생성
type StatusMap = Record<"active" | "inactive" | "banned", User[]>;

// Extract/Exclude
type SuccessEvents = Extract<Event, { type: "success" }>;

커스텀 유틸리티 타입

type DeepPartial<T> = {
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};

type NonNullableFields<T> = {
  [P in keyof T]: NonNullable<T[P]>;
};
TypeScriptUtility TypesGenerics

댓글 0

아직 댓글이 없습니다.