How can object property be referenced using bracket notation in TypeScript?
In traditional JavaScript, it can be done like this:
getValue(object, key) {
return object[key];
}
By calling
getValue({someKey: 1}, "someKey")
, the function will return 1
.
However, when attempting to do this in TypeScript, an error is encountered:
TS1003: Identifier expected. Name expected.
What is the correct way to achieve this in TypeScript?