类型“string[]"上不存在属性“includes" [英] Property 'includes' does not exist on type 'string[]'

查看:89
本文介绍了类型“string[]"上不存在属性“includes"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出现错误

'string[]' 类型不存在属性 'includes'

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

在 node_modules/ng2-breadcrumb/app/components/breadcrumbService.ts我正在尝试在 angular2 应用中实现面包屑功能.

in node_modules/ng2-breadcrumb/app/components/breadcrumbService.ts I am trying to implement breadcrumb functionality in an angular2 app.

推荐答案

"ES2017" 添加到 tsconfig.json 中的 "lib" 数组代码>:

Add "ES2017" to your "lib" array in tsconfig.json:

{
  "compilerOptions": {
    ...
    "lib": ["es6", "dom", "es2017"],
    ...
    "target": "es5",
    ...
  }
}

这应该从 TypeScript 2.1 开始工作.

This should work since TypeScript 2.1.

一个相关问题.

includes<从 ES7 (ES2016) 开始支持 Array 上的/code> 方法.以上将添加一个缺少的库文件进行编译.

The includes method on Array is supported since ES7 (ES2016). The above will add a missing library file to compilation.

TypeScript 编译器选项记录在此处.

The TypeScript compiler options are documented here.

Lib es2016es7 可能足以代替 es2017(未测试).

Lib es2016 or es7 may be sufficient instead of es2017 (not tested).

这篇关于类型“string[]"上不存在属性“includes"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆