Getting the error
Property 'includes' does not exist on type 'string[]'
in node_modules/ng2-breadcrumb/app/components/breadcrumbService.ts I am trying to implement breadcrumb functionality in an angular2 app.
The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.
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.
To fix the error "TS2339: Property 'x' does not exist on type 'Y'" with TypeScript, we should make sure the properties are listed in the interface that's set as the type of the object. interface Images { main: string; [key: string]: string; } const getMainImageUrl = (images: Images): string => { return images. main; };
The error "Property does not exist on type 'never'" occurs when we forget to type a state array or don't type the return value of the useRef hook. To solve the error, use a generic to explicitly type the state array or the ref value in your React application.
Add "ES2017"
to your "lib"
array in tsconfig.json
:
{ "compilerOptions": { ... "lib": ["es6", "dom", "es2017"], ... "target": "es5", ... } }
This should work since TypeScript 2.1.
A related issue.
The includes
method on Array
is supported since ES7 (ES2016). The above will add a missing library file to compilation.
The TypeScript compiler options are documented here.
Lib es2016
or es7
may be sufficient instead of es2017
(not tested).
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