![](/img/trans.png)
[英]Typescript Element implicitly has an 'any' type because expression of type 'any' can't be used to index type
[英]TypeScript: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Assignable'
有以下脚本
class Assignable {
constructor(properties: any) {
Object.keys(properties).map((key: string) => {
this[key as string] = properties[key]
})
}
}
抛出这个错误
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Assignable'.ts
知道为什么会发生这种情况以及如何解决它
你只需要在你的班级上创建索引:
class Assignable {
[key: string]: any;
constructor(properties: any) {
Object.keys(properties).forEach(key => {
this[key] = properties[key]
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.