You need to enable JavaScript to run this app. 使用react-select修改下拉框默认文本出现Missing return type on function报错如何处理
优惠活动
大模型
产品
解决方案
定价
更多

使用react-select修改下拉框默认文本出现Missing return type on function报错如何处理

报错原因

该报错由@typescript-eslint/explicit-function-return-typeESLint校验规则触发,规则要求所有函数必须显式声明返回值类型,你传入noOptionsMessage属性的匿名箭头函数没有标注返回类型。

解决方法
  • 方案1:给回调函数显式声明返回类型(最推荐,不修改全局规则)
    给箭头函数加string类型返回声明,修改后的属性配置为:
    noOptionsMessage={(): string => "please select list"}
    完整组件代码:
    <Select placeholder="Select Country" noOptionsMessage={(): string => "please select list"} />

  • 方案2:单行禁用规则
    如果仅不想修改这一处的代码,可以在对应代码行上方加ESLint忽略注释:

    {/* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */}
    <Select placeholder="Select Country" noOptionsMessage={() => "please select list"} />
    
  • 方案3:全局关闭/调整该规则
    如果项目不需要强制校验函数返回类型,可以修改ESLint配置文件(.eslintrc.js、.eslintrc.json等)中的规则配置:

    {
      "rules": {
        "@typescript-eslint/explicit-function-return-type": "off"
      }
    }
    

    也可以将规则值改为"warn",仅触发警告不阻断编译。

内容的提问来源于stack exchange,提问作者Nisha Kapoor

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.13 15:36:00