Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 1.4 KB

File metadata and controls

69 lines (52 loc) · 1.4 KB

Disallow variable redeclaration (no-redeclare)

Rule Details

This rule extends the base eslint/no-redeclare rule. It adds support for TypeScript function overloads, and declaration merging.

How to use

{
  // note you must disable the base rule as it can report incorrect errors
  "no-redeclare": "off",
  "@typescript-eslint/no-redeclare": ["error"]
}

Options

See eslint/no-redeclare options. This rule adds the following options:

interface Options extends BaseNoShadowOptions {
  ignoreDeclarationMerge?: boolean;
}

const defaultOptions: Options = {
  ...baseNoShadowDefaultOptions,
  ignoreDeclarationMerge: true,
};

ignoreDeclarationMerge

When set to true, the rule will ignore declaration merges between the following sets:

  • interface + interface
  • namespace + namespace
  • class + interface
  • class + namespace
  • class + interface + namespace
  • function + namespace

Examples of correct code with { ignoreDeclarationMerge: true }:

interface A {
  prop1: 1;
}
interface A {
  prop2: 2;
}

namespace Foo {
  export const a = 1;
}
namespace Foo {
  export const b = 2;
}

class Bar {}
namespace Bar {}

function Baz() {}
namespace Baz {}

Taken with ❤️ from ESLint core