【发布时间】:2020-06-22 22:40:17
【问题描述】:
我想索引一个正在构造并从函数返回的数组,但出现错误:
Element implicitly has an 'any' type because expression of type '3' can't be used to index type 'ArrFunc'.
Property '3' does not exist on type 'ArrFunc'
这是我在 Typescript 操场上重新创建的代码以显示我的问题。
type ArrFunc = () => number[];
const arrFunc:ArrFunc = () => [1, 2, 3, 4];
console.log(arrFunc[3]);
我不确定哪个“元素隐式具有‘任何’类型。”据我所知,上面示例中的所有内容都定义得很好。
提前致谢!
【问题讨论】:
标签: javascript typescript typescript-typings