如何在Typescript中获取对象的值
如何 我知道如何获得物体的钥匙。但是如何获取对象的值呢如何在Typescript中获取对象的值,typescript,Typescript,如何 我知道如何获得物体的钥匙。但是如何获取对象的值呢 const Obj={ A:‘A1’, B:‘B2’, C:‘C3’ } 类型键=对象类型的键;/'A'|'B'|'C' 类型值=???/'A1'|'B2'|'C3' 它只输出'string':typeof Obj[keyof typeof Obj]您必须将Obj声明为常量: const Obj = { A: 'A1', B: 'B2', C: 'C3' } as const
const Obj={
A:‘A1’,
B:‘B2’,
C:‘C3’
}
类型键=对象类型的键;/'A'|'B'|'C'
类型值=???/'A1'|'B2'|'C3'
它只输出'string':
typeof Obj[keyof typeof Obj]
您必须将Obj
声明为常量:
const Obj = {
A: 'A1',
B: 'B2',
C: 'C3'
} as const