gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:26:51 28 4
gpt4 key购买 nike

我正在使用 vue我刚刚更新了@typescript-eslint/eslint-plugin": "^3.10.1" .我的项目包含几个组件。其中一些正在使用javascript和其他 typescript .
警告
我对 中的方法有此警告非 typescript组件

warning: Missing return type on function (@typescript-eslint/explicit-module-boundary-types)


问题
我怎么不能在 .vue 上应用这条规则?未使用 <script lang="ts"> 的文件?

最佳答案

因此,此规则的目的是确保导出的模块对外部使用它的人有一个清晰的接口(interface)。来自 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 Rules
  • I get errors telling me "The file must be included in at least one of the projects provided"

  • If you do want to lint the file with type-aware linting:Check the include option of each of the tsconfigs that you provide to parserOptions.project - you must ensure that all files match an include glob, or else our tooling will not be able to find it.If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it tsconfig.eslint.json) in your project root which lists this file in its include. For an example of this, you can check out the configuration we use in this repo:tsconfig.eslint.json.eslintrc.js

    关于typescript - 停止 typescript-eslint/explicit-module-boundary-types 应用于不使用 Typescript 的 vue 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63609709/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com