【发布时间】:2016-04-19 01:23:58
【问题描述】:
所以我在 typescript 和 NodeJS 的数组上使用 findIndex ES6 函数时遇到了问题。
我得到的错误信息是:
requestType.findIndex 不是函数
这是我的代码:
let weatherStates:Array<string> = ['current', 'forecast'];
let requestType:string = 'current';
requestType.findIndex(weatherStates);
然后错误被抛出,不过我可以使用各种其他 ES6 功能,比如箭头函数等。
看起来 polyfill 在 lib.core.d.ts 类型中可用。
这里是 mytsconfig.json 设置:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true
},
"exclude": [
"node_modules",
"typings"
]
}
我是相当新的打字稿,所以任何帮助将不胜感激!
【问题讨论】:
-
1.
requestType是字符串,而不是数组 2。Array.prototype.index接受回调。也许你想要weatherStates.indexOf(requestType)? -
谢谢,帮了大忙!
标签: javascript node.js typescript ecmascript-6