Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...