How to get the property using the index of the key of an object in typescript?
Despite the error on TypeScript, the code works correctly.
My code
const payments = {
KEY1: {prop1: "prop1"},
KEY2: {prop1: "prop1"}
}
When I try to access by key value I got the error
const index = 0
const key = Object.keys(payments)[index]
const payment = payments[key] // ERROR HERE
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)
payments is of type object
const payments: { [key: string]: {prop1: string} } = {}