Mick Feller Mick Feller - 2 years ago 904
Javascript Question

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';

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": [

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download