Open1

TypeScript使用時のObject.entriesで型定義キャスト

phineszephinesze
const vectorData = {
    x: 80,
    y: 120,
    z: 10,
};

type Axis = keyof typeof vectorData;

(Object.entries(vectorData) as [Axis, number][]).map(([axis, value]) => {
  // axis が 'x' | 'y' | 'z' 型に
  // valueがnumber型に
})