CodingYang

vuePress-theme-reco Rackar    2018 - 2024
CodingYang CodingYang

Choose mode

  • dark
  • auto
  • light
首页
类别
  • 技术
  • 个人
  • 思考
  • 儿童
标签
时间线
联系
  • 关于
  • RSS订阅 (opens new window)
  • GitHub (opens new window)
  • 简书 (opens new window)
  • CSDN (opens new window)
  • WeChat (opens new window)
GitHub (opens new window)
author-avatar

Rackar

67

文章

44

标签

首页
类别
  • 技术
  • 个人
  • 思考
  • 儿童
标签
时间线
联系
  • 关于
  • RSS订阅 (opens new window)
  • GitHub (opens new window)
  • 简书 (opens new window)
  • CSDN (opens new window)
  • WeChat (opens new window)
GitHub (opens new window)
  • TypeScript中用for in遍历对象的属性

TypeScript中用for in遍历对象的属性

vuePress-theme-reco Rackar    2018 - 2024

TypeScript中用for in遍历对象的属性


Rackar 2020-03-23 TypeScript

在 TS 中使用对象遍历时,下角标不允许是字符串。

for (let k in obj) {
  let s = obj[k];
}
1
2
3

报错: Element implicitly has an ‘any’ type because expression of type ‘string’ can’t be used to index type ‘{ ..... }’. No index signature with a parameter of type ‘string’ was found on type ‘{..... }’.ts(7053)

解决办法为修改tsconfig.json,允许索引

"compilerOptions": {
    //...
    "suppressImplicitAnyIndexErrors": true
  },
1
2
3
4
参与编辑此文章 (opens new window)
更新于: 3/23/2020, 9:53:21 PM