判別可能なUnion型
Union型の判別(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") {
// Now TypeScript *knows* that `s` must be a square ;)
// So you can use its members safely :)
return s.size * s.size;
}
else {
// Wasn't a square? So TypeScript will figure out that it must be a Rectangle ;)
// So you can use its members safely :)
return s.width * s.height;
}
}網羅チェック(Exhaustive Checks)
スイッチ(Switch)
strictNullChecks
網羅チェックの中で例外を投げる
Retrospective Versioning
Redux
最終更新