打字稿,NodeJS,ES6 - 数组上的findIndex

时间:2016-04-19 01:23:58

标签: javascript node.js typescript ecmascript-6

所以我对在typescript和NodeJS中的数组上使用findIndex ES6函数有一个问题。

我得到的错误信息是:

  

requestType.findIndex不是函数

这是我的代码:

let weatherStates:Array<string> = ['current', 'forecast'];
let requestType:string = 'current';
requestType.findIndex(weatherStates);

然后错误被抛出,我可以使用各种其他ES6功能,例如箭头功能等。

看起来填充的lib.core.d.ts中可以使用polyfill。

这是mytsconfig.json设置:

{
"compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "sourceMap": true
},
"exclude": [
    "node_modules",
    "typings"
]
}

我是打字稿的新手,所以任何帮助都会非常感激!

1 个答案:

答案 0 :(得分:0)

requestType不是您示例中的数组。这是一个字符串。