当我使用 typescript@3.0.1 时,包含函数在 string[] 上不存在

includes function doesn't exist on string[] when I use typescript@3.0.1

例如

const arr: string[] = ['a', 'b', '3'];
arr.includes('a')

显示错误:

includes function isn't exist on string[]

我想知道 includes 函数存在于 Array 原型上,为什么不存在于 string[] 上? 我该如何解决这个问题?

您应该将 "es7" 添加到 tsconfig.json 的 "libs",像这样:

{
  "compilerOptions": {
    "lib": [
      "es7"
    ],
...