【发布时间】:2021-08-20 04:24:12
【问题描述】:
最终我想计算如下内容
const configOne = {
default: {master: 0},
sg: {master: 1},
}
const configTwo = {
default: {master: 1}
}
基本上object 必须有default 作为强制属性,然后其余属性可以是可选的,但它们必须是国家前缀。以下是我的尝试
enum CID {
'tw',
'sg',
'vn',
}
interface IIndividualConfig {
master: 0 | 1;
}
type IConfig = {
default: IIndividualConfig;
[key in CID]?: IIndividualConfig;
}
const configOne: IConfig = {
default: { master: 0 },
sg: {master: 1}
}
const configTwo: IConfig = {
default: { master: 1 }
}
下面是我在[key in CID]遇到的错误
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1170)
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
【问题讨论】:
标签: javascript typescript interface partial