Trying to use .includes in my component.ts file but it throws me the following error. help me in resolving the issue.
Property 'includes' does not exist on type 'string[]'
app.component.ts
permissionCookie: string[];
this.permissionCookie = cookieService.get("permissions").split(",");
this.permissionFlag = this.permissionCookie.includes("22");
ts.config
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}
this Property 'includes' does not exist on type 'string[]' didnt help me either
Try declaring it as,
private permissionCookie:Array<string>;
constructor() {
let a = this.permissionCookie.includes("22");
console.log(a);
}
tsconfig.json -->
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
// "moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
// "noImplicitAny": true,
// "suppressImplicitAnyIndexErrors": true,
"types": ["jquery"]
},
"exclude": [
"node_modules/*",
"**/*-aot.ts"
]
}
Add "ES2017" to your "lib" array in tsconfig.json:
{
"compilerOptions": {
...
"lib": ["dom", "es2017"],
...
}
}
This should work in TypeScript 2.1+.