keyof typeof で取得する。忘れそうなのでメモ。
const Aspects = {
"3x2": 3 / 2,
"4x3": 4 / 3,
"16x9": 16 / 9,
}
type Aspect = keyof typeof Aspects
// type Aspect = "3x2" | "4x3" | "16x9"
// と同じ
type AspectType = typeof Aspects
は
type AspectType = {
"3x2": number;
"4x3": number;
"16x9": number;
}
と同じ型定義を作る。で、keyof で key から Union 型を作る
type Aspect = keyof AspectType
一行で定義すると、冒頭の書き方になる。
type Aspect = keyof typeof Aspects