라벨이 유틸리티인 게시물 표시

[Typescript] TS 유틸리티 (Utility Types)

이미지
 Partial<Type> - Type의 모든 속성이 선택 사항으로 설정된 형식이다. interface A { a : string ; c : boolean ; d : number ; } const a : A = { a : ' aaa ' , c : false , d : 123 , }; const b : Partial < A > = { c : true , d : 123 , }; Readonly<Type> - 모든 속성이 읽기 전용으로 설정된 형식을 생성한다. 즉, 생성된 형식의 속성을 다시 할당할 수 없다. interface A { a : string ; c : boolean ; d : number ; } const a : A = { a : ' aaa ' , c : false , d : 123 , }; const b : Readonly < A > = { a : ' bbb ' , c : true , d : 123 , }; ReturnType<Type> - 어떤 함수의 return 값의 return 타입을 가져올 수 있다. declare function f1 (): { a : number ; b : string }; type T0 = ReturnType <() => string >; //type T0 = string type T1 = ReturnType <( s : string ) => void >; //type T1 = void type T2 = ReturnType << T >() => T >; //type T2 = unknown type T3 = ReturnType << T extends U , U exte