深度阅读

解决 TypeScript - Element implicitly has an 'any' type because expression of type ' string ' can't be used to index type

作者
作者
2023年08月22日
更新时间
3.39 分钟
阅读时间
0
阅读量

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

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。