Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'includes' does not exist on type 'string[]'

Tags:

typescript

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.

like image 381
ZeeAzmat Avatar asked Nov 11 '16 09:11

ZeeAzmat


People also ask

How do you fix property does not exist on type?

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.

Does not exist on type string TypeScript?

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.

Does not exist on type string TS 2339?

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

Does not exist on type never?

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.


1 Answers

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.

Explanation

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).

like image 113
mrkvon Avatar answered Sep 28 '22 10:09

mrkvon