简体   繁体   English

元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“{}”

[英]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.

相关问题 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“BGColors” - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'BGColors' 如何修复 Element 隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型? - how fix Element implicitly has an 'any' type because expression of type 'string' can't be used to index type? 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型 React Typescript - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type React Typescript 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“” - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '' 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型 - Phaser - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type - Phaser 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“{ AT: number; BE:数字,...}` - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ AT: number; BE: number,…}` 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型 A - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type A 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型样式 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type style TypeScript - 元素隐式具有“任意”类型,因为“字符串”类型的表达式不能用于索引类型 - TypeScript - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“{}” - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM