Search code examples
typescripteslinttypescript-eslint

Why does ESLint report a @typescript/no-redeclare error for a merged interface & variable?


My .eslintrc.json file looks like this:

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

I have this code (runnable here):

import React from 'react';

namespace Foo {
  // exported interface
  export interface Props {
    foo: string;
  }
}

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

When the code is linted, it yields the following error

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

According to typescript-eslint docs, I need to disable the base rule (see line 3 of the config file) and set ignoreDeclarationMerge to true (see line 7 of the config file).

Why is this still throwing an error?


EDIT: Note that this does not throw an error, as it is a function and not a const:

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

Solution

  • ignoreDeclarationMerge only works for the following cases:

    interface + interface
    namespace + namespace
    class + interface
    class + namespace
    class + interface + namespace
    function + namespace
    enum + namespace

    It won't work for namespace + variable