Notice the error message at the bottom: "config.ts(19,28): error TS2339: Property 'find' does not exist on type 'Answer[]". I thought all arrays would have a "find" method.
I am sure I am missing something!
To check if a TypeScript array contains an object:Pass a function to the Array. find() method. Check whether the identifier of the object is equal to a specific value and return true if it is. Array.
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the string type. To solve the error, use an object instead of a string, or make sure you're accessing a valid built-in method on the string.
The find() method returns the value of the first element that passes a test.
Since Typescript 2.0 you could also use the --lib
compiler flag or a "lib": []
section in your tsconfig.js
file to include ES6
features, while still targeting ES5
. See https://github.com/Microsoft/TypeScript/issues/6974
In this case just include the following configuration options in your tsconfig.js
:
... "lib": [ "es6" ], "target": "es5" ...
To answer your question it exists in TypeScript but not without some configurations.
To fix the issue you need to update your compilerOptions
as follows:
"compilerOptions": { "lib": ["es6"], "target": "es5" }
TypeScript 2.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With