noUnsafeDeclarationMerging
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/suspicious/noUnsafeDeclarationMerging
Since: v1.0.0
Sources:
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.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.ts:5:7 lint/suspicious/noUnsafeDeclarationMerging ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This class is unsafely merged with an interface.
3 │ }
4 │
> 5 │ class Foo {}
│ ^^^
6 │
7 │ const foo = new Foo();
ℹ The interface is declared here.
> 1 │ interface Foo {
│ ^^^
2 │ f(): void
3 │ }
ℹ The TypeScript compiler doesn’t check whether properties defined in the interface are initialized in the class.