[英]A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type
I have following type definition 我有以下类型定义
[Symbol(level)]?: string;
[Symbol(level)] ?:字符串;
I have tried 我努力了
importing level from winston and change the type to string|symbol but it doesn't resolve the problem. 从winston导入级别并将类型更改为string | symbol,但这不能解决问题。
It keep giving me following error "A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type." 它不断给我以下错误:“接口中的计算属性名称必须引用其类型为文字类型或“唯一符号”类型的表达式。”
any clue? 有什么线索吗? any pointer is helpful
任何指针都是有帮助的
Your symbol level
needs to be defined as a unique symbol
, like so: 您的符号
level
需要定义为unique symbol
,如下所示:
const level: unique symbol = Symbol();
Then modify your interface like this: 然后像这样修改您的界面:
interface MyInterface {
[level]?: string;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.