typeof型演算子
TypeScriptのtypeofは変数から型を抽出する型演算子です。次は、変数pointにtypeof演算子を用いて、Point型を定義する例です。
typescriptconst point = { x: 135, y: 35 };type Point = typeof point;
typescriptconst point = { x: 135, y: 35 };type Point = typeof point;
このPoint型は次のような型になります。
typescripttype Point = {x: number;y: number;};
typescripttype Point = {x: number;y: number;};
ここで説明したのはTypeScriptのtypeof型演算子です。JavaScriptのtypeof演算子と同じ名前ですが、まったく別のものなので注意してください。