oxc-project/oxc · error

Unsafe declaration merging between classes and interfaces.

Error message

Unsafe declaration merging between classes and interfaces.

What it means

Lint diagnostic from typescript/no-unsafe-declaration-merging: a class and an interface share the same name in the same scope. Declaration merging makes the class claim the interface's (uninitialized) properties, and since tsc does not check property initialization for merged interfaces, this can hide runtime errors.

Source

Thrown at crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs:14

use oxc_ast::{AstKind, ast::BindingIdentifier};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::SymbolId;
use oxc_span::Span;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    rule::Rule,
};

fn no_unsafe_declaration_merging_diagnostic(span: Span, span1: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unsafe declaration merging between classes and interfaces.")
        .with_help("The TypeScript compiler doesn't check whether properties are initialized, which can lead to TypeScript not detecting code that will cause runtime errors.")
        .with_labels(if span < span1 { [span, span1]} else { [span1, span] })
}

#[derive(Debug, Default, Clone)]
pub struct NoUnsafeDeclarationMerging;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow unsafe declaration merging.
    ///
    /// ### Why is this bad?
    ///
    /// Declaration merging between classes and interfaces is unsafe.
    /// The TypeScript compiler doesn't check whether properties are initialized, which can lead to TypeScript not detecting code that will cause runtime errors.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rename the interface (e.g. Foo -> FooInterface) or the class so they no longer merge
  2. Fold the interface members into the class declaration
  3. Delete the interface if it is redundant
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_unsafe_declaration_merging.rs:14 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/6be28bbae96beb63. Report an issue: GitHub.