Typescript: Property 'find' does not exist on type

Created on 18 Jan 2019  ·  4Comments  ·  Source: microsoft/TypeScript

"typescript": "^3.2.2"

Search Terms: Property 'find' does not exist on type

Code

https://github.com/mariohmol/gherkin/blob/master/index.ts#L17

const found = c.students.find(s => s === student);

Running tsc index.ts

Config:
https://github.com/mariohmol/gherkin/blob/master/tsconfig.json#L8

Expected behavior: Compile sucessfully

Actual behavior:
https://travis-ci.org/mariohmol/gherkin/jobs/481149988#L446

index.ts:17:34 - error TS2339: Property 'find' does not exist on type 'Student[]'.

17         const found = c.students.find(s => s === student); 

Playground Link: https://github.com/mariohmol/gherkin

Related Issues: https://github.com/Microsoft/TypeScript/issues/6945

External

Most helpful comment

@mariohmol You're using the TypeScript compiler wrong.

https://travis-ci.org/mariohmol/gherkin/jobs/481159659#L447

When you invoke the tsc compiler by providing a list of filenames, then the tsconfig.json will NOT be used. You need to specify all compiler flags you want yourself then. As a result the default compiler flags are used and an old ES version is targeted that does not provide Array.find.

From the tsconfig documentation:

When input files are specified on the command line, tsconfig.json files are ignored.

@DanielRosenwasser likely didn't follow your step to invoke tsc index.ts when trying to reproduce this issue.

All 4 comments

Worked for me when I cloned it, but with issues around document not being defined since you're not including the DOM:

Cannot find name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.

Thanks for quick response!

I separated the class from the rest:

https://travis-ci.org/mariohmol/gherkin/jobs/481159659#L447
https://github.com/mariohmol/gherkin/blob/master/classes.ts

same issue =(

@mariohmol You're using the TypeScript compiler wrong.

https://travis-ci.org/mariohmol/gherkin/jobs/481159659#L447

When you invoke the tsc compiler by providing a list of filenames, then the tsconfig.json will NOT be used. You need to specify all compiler flags you want yourself then. As a result the default compiler flags are used and an old ES version is targeted that does not provide Array.find.

From the tsconfig documentation:

When input files are specified on the command line, tsconfig.json files are ignored.

@DanielRosenwasser likely didn't follow your step to invoke tsc index.ts when trying to reproduce this issue.

@MartinJohns you rocks!

Was this page helpful?
0 / 5 - 0 ratings