Extract<T, U>
개념
한마디로, T에서 U타입 중 할당 가능한 것만 리턴
정리하지면, pick
은 prop을, extract
는 type을...
type Extract<T, U> = T extends U ? T : never
Examples
type Company = {
id: string
name: string
}
type Product = {
price: number
rating: number
}
type fakeProduct = Extract<Company | Product, Company>
// type fakeProduct = {
// id: string;
// name: string;
// }
참고
https://velog.io/@ggong/Typescript의-유틸리티-타입-1-Record-Extract-Pick