A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type

11,282

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;
}
Share:
11,282

Related videos on Youtube

user269867
Author by

user269867

Updated on June 04, 2022

Comments

  • user269867
    user269867 almost 2 years

    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