(https://www.typescriptlang.org/docs/handbook/2/mapped-types.html)
JavaScript에서 배열에 map을 이용하는 것처럼 type에서도 map을 이용한 것과 같이 적용할 수 있다.
// 위 링크에서 발췌
type OnlyBoolsAndHorses = {
[key: string]: boolean | Horse;
};
const conforms: OnlyBoolsAndHorses = {
del: true,
rodney: false,
};
(https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
조건을 줄 수도 있다.
interface Animal {
live(): void;
}
interface Dog extends Animal {
woof(): void;
}
type Example = Dog extends Animal ? number : string;
https://www.typescriptlang.org/docs/handbook/utility-types.html)
타입스크립트가 제공하는 몇 가지 유틸 타입이 있다.
Partial
: 해당 type의 모든 key를 Optional
하게 만듬Required
: Partial
의 반대. 모두 반드시 필요하게 만듬Readonly
: 해당 type의 모든 값을 변경할 수 없도록 만듬Pick
: 해당 type의 일부만 선택하도록 함 (Pick<Person, "name" | "age">
)Omit
: Pick
의 반대. 빼고싶은 key를 선택하도록 함이외에도 많은 유틸 타입이 있다.
(꼭 한번씩 사용해보기⭐)
멋져멋져