Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '...'. Ошибка
Primary tabs
Получаем ошибку:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'RootActionTypesListType'. No index signature with a parameter of type 'string' was found on type 'RootActionTypesListType'. TS7053 11 | 12 | for (const key of Object.keys(RootActionTypes)) { > 13 | RootActionTypes[key] = 'ROOT_' + key; | ^ 14 | } 15 | RootActionTypes = Object.freeze(RootActionTypes); 16 |
Для кода вида:
type RootActionTypesListType = { SET_GOODS_LIST_DATA: string | null, RESET_GOODS_LIST: string | null , } let RootActionTypes: RootActionTypesListType = { SET_GOODS_LIST_DATA: null, RESET_GOODS_LIST: null }; for (const key of Object.keys(RootActionTypes)) { RootActionTypes[key] = 'ROOT_' + key; }
Решение
Нужно задать типы ключей объекта, для неявного их вызова, т.е. напр. можно переделать определение типа с:
type RootActionTypesListType = { SET_GOODS_LIST_DATA: string | null, RESET_GOODS_LIST: string | null , }
на:
type RootActionTypesListType = { [key: string]: string | null, }
- Log in to post comments
- 2412 reads