Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.05 KB

no-unsafe-declaration-merging.md

File metadata and controls

54 lines (36 loc) · 1.05 KB
description
Disallow unsafe declaration merging.

🛑 This file is source code, not the primary documentation location! 🛑

See https://typescript-eslint.io/rules/no-unsafe-declaration-merging for documentation.

TypeScript's "declaration merging" supports merging separate declarations with the same name.

Declaration merging between classes and interfaces is unsafe. The TypeScript compiler doesn't check whether properties are initialized, which can cause lead to TypeScript not detecting code that will cause runtime errors.

interface Foo {
  nums: number[];
}

class Foo {}

const foo = new Foo();

foo.nums.push(1); // Runtime Error: Cannot read properties of undefined.

Examples

❌ Incorrect

interface Foo {}

class Foo {}

✅ Correct

interface Foo {}
class Bar implements Foo {}

namespace Baz {}
namespace Baz {}
enum Baz {}

namespace Qux {}
function Qux() {}

Further Reading