简体   繁体   中英

Typescript, NodeJS, ES6 - findIndex on array

So i have an issue with using findIndex ES6 function on an array in typescript and NodeJS.

The error message i'm getting is:

requestType.findIndex is not a function

this is my code:

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

and then the error gets thrown, i'm able to use all sorts of other ES6 functionalities though, like the arrow functions etc.

it looks like that the polyfill is available in the lib.core.d.ts typing though.

Here is mytsconfig.json setup:

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

i'm fairly new with typescript so any help would be greatly appreciated!

requestType is not an array in your example. It is a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM