You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在不关闭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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 22:30:05