开发 · 12月 7, 2022 0

解决 TypeScript – Element implicitly has an ‘any’ type because expression of type ‘ string ‘ can’t be used to index type

内容纲要

解决 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

%d 博主赞过: