解决 TypeScript - Element implicitly has an 'any' type because expression of type ' string ' can't be used to index type
Published on Aug. 22, 2023, 12:11 p.m.
解决 TypeScript - Element implicitly has an ‘any’ type because expression of type ‘ string ‘ can’t be used to index type
const color : any = {
red: null,
green: null,
blue: null
};
可以尝试使用强制类型,如下:
const color : { [key: string]: any } = {
red: null,
green: null,
blue: null
};
More information on indexing in TypeScript: Index Signatures