IT/typescript32 TS - Extract<T, U> 개념 한마디로, T에서 U타입 중 할당 가능한 것만 리턴 정리하지면, pick은 prop을, extract는 type을... type Extract = T extends U ? T : never Examples type Company = { id: string name: string } type Product = { price: number rating: number } type fakeProduct = Extract // type fakeProduct = { // id: string; // name: string; // } 참고 https://velog.io/@ggong/Typescript의-유틸리티-타입-1-Record-Extract-Pick 2023. 6. 27. TS - Exclude<T, U> 개념 한마디로, T에서 U를 제외시킨 Type U를 제외시킬 수 없다면 T 그대로 리턴 T에 union type 받을 수 있음 type Exclude = T extends U ? never : T Examples Only number type numberOnly = Exclude const a: numberOnly = 5 // const a: number how it works Exclude => Exclude | Exclude => string | never => => string Remove props in interface interface Student { name: string age: number address: string gpa: number } type refiendStudent = Ex.. 2023. 6. 27. 이전 1 ··· 3 4 5 6 다음