Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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

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;
                Whoa. I was wanting to do [typeof level]?: string; because level is a runtime value, and we want the type. Weird.
– trusktr
                Jan 30 at 1:05
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.