2

I'm trying to use enum as a reference to another enum. Even though it works, TS gives an error.

enum One {
    some = 'some text here',
    other = 'other stuff here'
}

enum Two {
    thing = 'some',
    whatever = 'other'
}

Object.keys(Two).forEach(k =>  console.log(One[Two[k]]))
                                           ~~~~~~~~~~~
// Console:
// some text here
// other stuff here

Gives the follow error:

Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'typeof One'.(7053)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof Two'.

No index signature with a parameter of type 'string' was found on type 'typeof Two'.(7053)

skube
  • 5,867
  • 9
  • 53
  • 77

0 Answers0