close

no-unsafe-declaration-merging

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unsafe-declaration-merging': 'error',
    },
  },
]);

Rule Details

Disallows unsafe declaration merging between a class and an interface. TypeScript allows a class and an interface that share the same name in the same scope to merge into a single declaration. Properties declared on the interface are added to the resulting type without forcing the class to actually initialize them, so accessing such a property on a class instance type-checks but throws Cannot read properties of undefined at runtime.

Examples of incorrect code for this rule:

interface Foo {}
class Foo {}
class Foo {}
interface Foo {}
declare global {
  interface Foo {}
  class Foo {}
}

Examples of correct code for this rule:

interface Foo {}
class Bar implements Foo {}
namespace Foo {}
namespace Foo {}
enum Foo {}
namespace Foo {}
namespace Qux {}
function Qux() {}
const Foo = class {};
interface Foo {
  props: string;
}

function bar() {
  return class Foo {};
}
declare global {
  interface Foo {}
}

class Foo {}

Original Documentation