読み方のヒント
矢印ボタン(または ← → キー)でページを移動できます。
| で型をつなぐと、「どれか1つ」を表す型になります。
type ProductCategory = "bread" | "pastry" | "savory" | "sweets";
type PickupInput = string | Date;
type FoundProduct = Product | undefined;
| 型 | 入る値 |
|---|---|
"bread" | "pastry" | ... | 4つの文字列のどれか |
string | Date | 文字列か、日付の値 |
Product | undefined | 商品か、undefined |
このような型を、ユニオン型と呼びます。前の章までに使った string | null や、find の戻り値の Product | undefined も、ユニオン型です。
2 / 17