I have an object and I want to access the object value using a string index, but when I try to do that in TypeScript, I'm getting errors.
// Declared Globally
const Orientation = {
value: () => 0,
'next_value': () => someFunction.anotherFunction.sqrt(),
};
// _textValue type declared
_textValue : string;
// Declared inside constructor
this._textValue = 'next_value';
// value used inside a function
_getValue(){
const newValue = Orientation[this._textValue]();
}
And where I use Orientation[this._textValue]();
, I'm getting the error as:
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ value: () => number; 'next_value': () => number; }'.ts(7053)
Any idea on how to resolve this?