我想动态定义我的接口对象键,其中键名来自变量。有没有办法做到这一点?
我目前收到了上述错误信息:
const key1 = 'hello';
const key2 = 'world';
interface MyInterface {
[key1]: {};
[key2]: string;
}
const myObject: MyInterface = {
[key1]: {
something: 'something',
},
[key2]: 'some other things'
}
我目前收到了上述错误信息:
谢谢。接口中的计算属性名必须直接引用内置符号