구별된 유니온
구별된 유니온(Discriminated Union)
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
type Shape = Square | Rectangle;function area(s: Shape) {
if (s.kind === "square") {
// 이것으로 TypeScript가 `s`가 `Square`임을 알게 됨 ;)
// 그러므로 `Square`의 멤버를 안전하게 사용할 수 있음 :)
return s.size * s.size;
}
else {
// `Square`가 아님? 그러면 TypeScript는
// 이것이 `Rectangle`일 수 밖에 없음을 알게 됨 ;)
// 그러므로 `Rectangle`의 멤버를 안전하게 사용할 수 있음 :)
return s.width * s.height;
}
}빠짐없는 검사(Exhaustive Check)
Switch
strictNullChecks
완전 검사에서 Throw
회고적(Retrospective) 버전 관리
Redux
Last updated