笑话类型定义不适用于Typescript项目 问题

问题描述

我从GTS开始了一个新的Typescript项目。对于常规的* .ts文件,键入工作正常,但我尝试过的任何方法都无法使* .spec.ts文件正常工作。

问题

ESLint在VS代码中将每个笑话功能标记为红色。该消息将显示“(定义|描述|期望)未定义”。我尝试过包括和排除文件添加类型以及从其他项目复制。

这是我当前的tsconfig

{
  "compileOnSave": false,"extends": "./node_modules/gts/tsconfig-google.json","compilerOptions": {
    "rootDir": "./src","outDir": "./dist","sourceMap": true,"declaration": true,"moduleResolution": "node","emitDecoratorMetadata": true,"experimentalDecorators": true,"importHelpers": true,"target": "es2015","module": "esnext","typeRoots": ["node_modules/@types"],"lib": ["es2017","dom"],"skipLibCheck": true,"skipDefaultLibCheck": true,"baseUrl": ".","types": ["node","jest"]
  },"exclude": ["**/*.spec.ts"],"include": ["src/**/*.ts","tests/**/*.ts"]
}

根目录很简单

相关软件包:

"@types/jest": "^26.0.14","@types/node": "^13.11.1","gts": "^2.0.2","jest": "^26.4.2","tslint": "^6.1.3","typescript": "^4.0.3"

我的配置中有明显的错误吗?我应该有2个配置,一个用于ts,另一个用于spec吗?

解决方法

问题是 ESLint配置。我将此添加到.eslintrc.json文件中,错误消失了:

"env": {
    "browser": true,"es6": true,"jest": true,"node": true
  },