indicator.indicator_threshold![index] = threshold;也报错Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'number | (number | null)[]'.
时间: 2024-02-01 19:03:57 浏览: 130
这个报错是因为 TypeScript 不确定 `indicator_threshold` 属性的类型。可以在定义 `indicator_threshold` 属性时加上类型,例如:
```
interface Indicator {
indicator_threshold: (number | null)[];
}
let indicator: Indicator = { indicator_threshold: [] };
const index = 0;
const threshold = 10;
indicator.indicator_threshold[index] = threshold;
```
这样 TypeScript 就能够正确推断 `indicator_threshold` 属性的类型,并且就不会报错了。
阅读全文