Reputation: 5508
I am learning TypeScript and I have got version 4.0.5 installed. My problem is that i have variable with array of numbers:
const arrayOfNumbers: number[] = [];
And later I am pushing some numbers into it and later I want to find some numbers inside.
arrayOfNumbers.find(el => el === index)
Which throws me an error:
Property 'find' does not exist on type 'number[]'.
But on intellisense I can see find method.
Upvotes: 1
Views: 6828
Reputation: 1
You can do this by adding the following line to your
tsconfig.json file:"lib": ["e2015"]
After this you may face console.log () error for this if your code is running in a browser environment, you need to add “Dom” to the lib array in your tsconfig.json file, which tells the compiler to include the type definitions for built-in JavaScript APIs found in browser environments, such as the console object. For example:
"lib": [
// other libs...
"es6",
"dom"
]
Upvotes: 0
Reputation: 305
Update your tsconfig to target ES2015 or above.
For single file compilations
tsc {filepath} --lib es6
You can reproduce the error here: Typescript Playground
Upvotes: 2
Reputation: 5508
The problem here is with tsc compiler. When I want to transplie ts file by using filename:
tsc index.ts
It ignores tsconfig.json. When I transplie simply with:
tsc
An error has gone and I can use now find method from ES6
Source: https://github.com/Microsoft/TypeScript/issues/29473#issuecomment-455601893
Upvotes: 2