尝试在我的component.ts文件中使用.include,但它会引发以下错误。帮助我解决问题。
财产&#39>包括'类型'字符串[]'
上不存在
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"
]
}
}
这Property 'includes' does not exist on type 'string[]'对我没有任何帮助
答案 0 :(得分:0)
尝试将其声明为,
private permissionCookie:Array<string>;
constructor() {
let a = this.permissionCookie.includes("22");
console.log(a);
}
tsconfig.json - &gt;
{
"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"
]
}
答案 1 :(得分:-1)
将"ES2017"
添加到"lib"
中的tsconfig.json
数组:
{
"compilerOptions": {
...
"lib": ["dom", "es2017"],
...
}
}
这应该适用于TypeScript 2.1 +。