typescript - 停止 typescript-eslint/explicit-module-boundary-types 应用于不使用 Typescript 的 vue 组件
问题描述
我正在使用vue
,我刚刚更新了@typescript-eslint/eslint-plugin": "^3.10.1"
. 我的项目包含几个组件。他们中的一些人正在使用javascript
和其他人typescript
。
警告
我对非 typescript
组件内的方法有此警告
警告:函数缺少返回类型(@typescript-eslint/explicit-module-boundary-types)
问题
我怎么能不对.vue
不使用的文件应用此规则<script lang="ts">
?
解决方案
因此,此规则的目的是确保导出的模块对外部使用它的人有一个清晰的接口。从规则页面.ts
来看,用for files代替files似乎是有道理的.vue
,但是你可以根据你的项目需求来判断。
对于我的项目,我使用了建议的overrides
配置:
{
"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"]
}
}
]
}
除此之外,我认为你不能filters
说on the caught .vue files by eslint, only apply the rule on the ones matched by: 'having <script lang="ts">'
。
也许您最好对这些具体错误使用内联注释。
编辑
我看到的另一个解决方案可能是在文件中手动列出您的.eslint.config
文件。
也可以看看
如果您确实想使用类型感知 linting 对文件进行 lint:检查您提供给 parserOptions.project 的每个 tsconfig 的包含选项 - 您必须确保所有文件都与包含 glob 匹配,否则我们的工具将无法找到它。如果您的文件不应该是现有 tsconfig 的一部分(例如,它是存储库本地的脚本/工具),那么请考虑在您的项目根目录在其包含中列出了此文件。例如,您可以查看我们在此 repo 中使用的配置:tsconfig.eslint.json .eslintrc.js
推荐阅读
- java - 如何将带有页码的目录添加到 RTF
- java - 当我调用spring data JPA分页查询时,抛出'PageImpl:找不到合适的构造函数,无法反序列化'
- java - JAVA CardView 在 SDK 版本 28 中消失
- php - 尝试按日期对一系列 WordPress 帖子进行排序,最后使用空值
- java - 与 jdbc 相比,Hibernate(PostgreSQL)外键上的慢速选择查询 WHERE 子句
- javascript - 力有向图的链接端点总是粘在矩形节点的左角
- c++ - 为什么 range-v3 库中缺少 interleave_view?
- javascript - 如何在javascript函数中执行python代码(.py文件)?
- azure-active-directory - O365 - 无法在 SPPagecontextinfo 中获取访客用户电子邮件
- html - 在 CSS 中移动图像