简体   繁体   English

接口中的计算属性名称必须引用其类型为文字类型或“唯一符号”类型的表达式

[英]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.

相关问题 class 实现的接口类型中缺少属性 - Property is missing in type which is an interface implemented by class graphQL-类型必须为输出类型 - graphQL - type must be Output Type 根据参数计算返回类型 - Computed return type based on parameters 类型“ContactComponent”上不存在属性“名称” - Property 'name' does not exist on type 'ContactComponent' Nodejs 14.5 文件系统 API Dirent “Symbol(type)” 属性是什么? - Nodejs 14.5 Filesystem API what is the Dirent “Symbol(type)” property? 对于此错误是否有任何替代方法 - 声明类型既不是“void”也不是“any”的函数必须返回一个值? - Is there any alternative to this error - A function whose declared type is neither 'void' nor 'any' must return a value? LambdaFunction - 属性变量的值必须是具有字符串(或简单类型)属性的对象 - LambdaFunction - Value of property Variables must be an object with String (or simple type) properties 类型错误:“config.server”属性是必需的,必须是字符串类型 - TypeError: The "config.server" property is required and must be of type string “config.options.port”属性必须是数字类型 - ENV - The “config.options.port” property must be of type number - ENV gulp 生成 TypeError: The Streams property must be of type function - gulp generates TypeError: The Streams property must be of type function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM