Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

I have tried

importing level from winston and change the type to string|symbol but it doesn't resolve the problem.

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

like image 335
user269867 Avatar asked Sep 11 '19 21:09

user269867


1 Answers

Your symbol level needs to be defined as a unique symbol, like so:

const level: unique symbol = Symbol();

Then modify your interface like this:

interface MyInterface {
    [level]?: string;
}
like image 153
Sam A. Horvath-Hunt Avatar answered Sep 28 '22 18:09

Sam A. Horvath-Hunt