0

I have an object which looks something like this

interface atype {
 A: number;
 B: number;
}


const a: atype = {
 A: 1,
 B: 2
}

I would like to access the value of a property of a depending on a given string with the key. i.e.

const val = a.[key]

this works but I get the error Identifier expected. now if I try doing

const val = a[key]

Now I get the error

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'atype'.
No index signature with a parameter of type 'string' was found on type 'atype'.

Could someone help me figure out how to do this w/o any errors/warnings

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
user15032172
  • 55
  • 1
  • 6

0 Answers0