停止不使用Typescript的typescript-eslint / explicit-module-boundary-types应用于vue组件 警告问题

问题描述

我正在使用vue,并且刚刚更新了@typescript-eslint/eslint-plugin": "^3.10.1"。我的项目包含几个组件。其中一些使用javascript,另一些使用typescript

警告

我对 typescript组件内部的方法发出此警告

警告:函数缺少返回类型(@ typescript-eslint / explicit-module-boundary-types)

问题

我如何不能在未使用.vue的{​​{1}}文件上应用此规则?

解决方法

因此,此规则的目的是确保导出的模块与任何在外部使用该模块的人都有清晰的接口。从rule page看来,使用.ts文件而不是.vue文件似乎很有意义,但是您可以根据项目需求进行判断。

在我的项目中,我使用了suggested overrides configuration

{
  "rules": {
    // disable the rule for all files
    "@typescript-eslint/explicit-module-boundary-types": "off"
  },"overrides": [
    {
      // enable the rule specifically for TypeScript files
      "files": ["*.ts","*.tsx"],"rules": {
        "@typescript-eslint/explicit-module-boundary-types": ["error"]
      }
    }
  ]
}

除此之外,我认为您无法filterson the caught .vue files by eslint,only apply the rule on the ones matched by: 'having <script lang="ts">'

对于这些具体错误,也许最好使用inline comments

修改

我看到的另一种解决方案可能是在.eslint.config文件中手动列出文件。

有关想法,请参见Extending your TypeScript linting with Type-Aware RulesI get errors telling me "The file must be included in at least one of the projects provided"

如果您确实想使用类型识别的棉绒来绒毛文件: 检查您提供给parserOptions.project的每个tsconfig的include选项-您必须确保所有文件都匹配一个include glob,否则我们的工具将找不到它。 如果您的文件不应该属于现有tsconfig的一部分(例如,它是存储库本地的脚本/工具),请考虑在您的文件中创建一个新的tsconfig(建议将其命名为tsconfig.eslint.json)项目根目录,该目录在其include中列出该文件。例如,您可以查看此仓库中使用的配置: tsconfig.eslint.json .eslintrc.js