相关疑难解决方法(0)

为什么Object.keys不返回TypeScript中的keyof类型?

标题说明了一切-为什么Object.keys(x)在TypeScript 中不返回类型Array<keyof typeof x>?就是这样Object.keys做的,因此对于TypeScript定义文件作者来说,似乎很明显的疏忽是不将返回类型简单地设为keyof T

我应该在他们的GitHub存储库上记录错误,还是继续发送PR为其进行修复?

typescript

32
推荐指数
3
解决办法
2410
查看次数

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

Trying out TypeScript for a React project and I'm stuck on this error:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ train_1: boolean; train_2: boolean; train_3: boolean; train_4: boolean; }'.
  No index signature with a parameter of type 'string' was found on type '{ train_1: boolean; train_2: boolean; train_3: boolean; train_4: boolean; }'
Run Code Online (Sandbox Code Playgroud)

Which appears when I try to filter the array in my component

.filter(({ name }) => plotOptions[name]); …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

6
推荐指数
13
解决办法
4917
查看次数

标签 统计

typescript ×2

reactjs ×1