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

为何合并接口与变量时ESLint仍报@typescript/no-redeclare错误?

配置@typescript-eslint/no-redeclare后仍触发重复定义错误的疑问

ESLint配置

我的.eslintrc.json配置如下:

{
  "rules": {
    "no-redeclare": "off",
    "@typescript-eslint/no-redeclare": [
      "error",
      {
        "ignoreDeclarationMerge": true
      }
    ]
  }
}

触发错误的代码

我编写了如下代码:

import React from 'react';

namespace Foo {
  // 导出的接口
  export interface Props {
    foo: string;
  }
}

export const Foo: React.FC<Foo.Props> = ({ foo }) => {
  return foo;
};

报错信息

代码lint时出现如下错误:

'Foo' is already defined. 10:14 - 10:38

疑问

根据typescript-eslint的文档,我已经禁用了ESLint基础的no-redeclare规则,并且将@typescript-eslint/no-redeclare的ignoreDeclarationMerge设为true,但为什么还是会触发重复定义的错误?

补充说明:换成函数形式就不会触发错误,代码如下:

export function Foo({ foo }): React.FC<Foo.Props> {
  return foo;
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 21:05:00