TypeScript ESLint 解析器

问题描述 投票:0回答:1

根据文档所说,tsc解析器某些规则需要tsconfig 需要以下类型的信息:

“airbnb-typescript”,“插件:@typescript-eslint/推荐的需要类型检查” 规则。

但是尽管我使用了 tsconfig,但我没有看到任何区别 在那个规则中。这些规则到底在哪里使用 tsconfig 以及什么 他们到底读到了什么?谢谢你。

eslint

module.exports = {
  root: true,
  parser: "@typescript-eslint/parser",
  env: {
    browser: true,
  },
  parserOptions: {
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
    },
    project: ["./tsconfig.json"],
  },

  extends: [
    "airbnb",
    "airbnb-typescript",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
  ],
  ignorePatterns: ["/*.*"],
};

tsconfig

{
  "compilerOptions": {
    "allowJs": true, 
    // "alwaysStrict": true,
    // "esModuleInterop": false, 
    "allowSyntheticDefaultImports": false,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true, 
    "jsx": "preserve",
    "lib": ["dom", "ES2015"], 
    "noEmit": true, 
    "module": "es6", 
    "moduleResolution": "node",
    "target": "es5", 
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "outDir": "./typescriptDist"
  },
  "exclude": ["node_modules"],
  "include": ["app/**/*"]
}
angular typescript tsconfig
1个回答
0
投票

"plugin:@typescript-eslint/recommended-requiring-type-checking",
行是添加使用类型信息的规则的内容。在提出这个问题后,文档被添加到 typescript-eslint.io 中:

tl;dr:“类型检查”规则使用 TypeScript 的类型 API 来请求有关代码的 types 的信息。此类信息需要 TSConfig(最常见的是

tsconfig.json
)并读取代码库中潜在的许多文件(例如,了解导入值的类型)。这使得这些规则变慢 但比传统的 linting 规则更强大。

例如,

@typescript-eslint/await-thenable
会标记非“Thenable”(最常见的是
await
)前面的任何
Promise
。不必要的
await
可能是死代码的标志。但是要知道等待的值是否是 Thenable 通常需要类型信息。

© www.soinside.com 2019 - 2024. All rights reserved.