[英]Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'
Also has getting this error ' No index signature with a parameter of type 'string' was found on type '{}''还出现此错误“在类型“{}”上找不到带有“字符串”类型参数的索引签名
const dnsListObj = {};
for (const key of dnsList) {
dnsListObj[key.id] = key.ipAddr;
}
whats wrong in my code.我的代码有什么问题。 please help.
请帮忙。
const dnsListObj : {[key:string] : any } = {};
for (const key in dnsList) {
dnsListObj[key.id] = key.ipAddr;
}
You can type your dnsListObj so it can accept indexes of type string您可以键入您的 dnsListObj,以便它可以接受字符串类型的索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.