【发布时间】:2017-09-23 15:29:15
【问题描述】:
尝试在我的 component.ts 文件中使用 .includes 但它会引发以下错误。帮我解决问题。
- 错误
类型“string[]”上不存在属性“includes”
-
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[]' 也没有帮助我
【问题讨论】:
-
this.permissionCookie - 这是一个数组吗?包含仅适用于数组。
-
您说您发布的链接中的解决方案不起作用,但您的配置根本没有使用它。它说使用
es2016作为目标而你不是。当includes是 ES2016 的一部分时,其他所有内容都设置为 ES6。 -
是的,它是...@RemyaJ
-
@GillesC 我的意思是我尝试将目标更改为 es2016 的方式,尽管它没有工作
标签: angular typescript