src/content/docs/linter/rules/no-unsafe-declaration-merging.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/suspicious/noUnsafeDeclarationMerging`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`@typescript-eslint/no-unsafe-declaration-merging`](https://typescript-eslint.io/rules/no-unsafe-declaration-merging){
"linter": {
"rules": {
"suspicious": {
"noUnsafeDeclarationMerging": "error"
}
}
}
}
Disallow unsafe declaration merging between interfaces and classes.
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 defined in the interface are initialized in the class. This can cause lead to TypeScript not detecting code that will cause runtime errors.
interface Foo {
f(): void
}
class Foo {}
const foo = new Foo();
foo.f(); // Runtime Error: Cannot read properties of undefined.
interface Foo {}
class Bar implements Foo {}
namespace Baz {}
namespace Baz {}
enum Baz {}