如何在不关闭explicit-module-boundary-types规则前提下移除TS ESLint函数返回类型缺失警告
解决方案
@typescript-eslint/explicit-module-boundary-types 规则支持单独配置校验维度,你可以通过调整规则参数,在保留入参类型校验的前提下关闭返回类型检查,无需完全禁用该规则。
操作方法
在你现有的 .eslintrc.js 的 rules 配置项中添加如下规则:
"@typescript-eslint/explicit-module-boundary-types": ["warn", { // 关闭返回类型缺失校验 "allowMissingReturnType": true, // 保留入参类型缺失校验 "allowMissingParameterType": false }]
修改后完整配置参考
module.exports = { parser: '@typescript-eslint/parser', plugins: ["deprecation", '@typescript-eslint'], extends: [ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier", ], parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, rules: { "deprecation/deprecation": "warn", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-object-literal-type-assertion": "off", "@typescript-eslint/explicit-function-return-type": "off", // 新增规则配置 "@typescript-eslint/explicit-module-boundary-types": ["warn", { "allowMissingReturnType": true, "allowMissingParameterType": false }] }, };
内容的提问来源于stack exchange,提问作者Picci
相关产品推荐
相关产品推荐

