myObject = {
field1: 'value1',
field2: 'value2'
}
const key:string = 'field1';
const fvalue = myObject[key]
пишет
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ field1: string; field2: string; }'.
No index signature with a parameter of type 'string' was found on type '{ field1: string; field2: string; }'
что не так делаю?
const myObject: {[key: string]: string} = { field1: 'value1', fiels2: 'value2' }
Обсуждают сегодня