リテラル型を使って、特定の値のみを受け入れる型を定義する方法を学びます。文字列、数値、真偽値のリテラルを組み合わせます。
// 文字列リテラル型type Status = | | ;let currentStatus: Status = "success";// 数値リテラル型(1〜6)type DiceValue = | | | | | ;let dice: DiceValue = 3;// 真偽値リテラル型type YesOrNo = | ;let answer: YesOrNo = true;