oxc-project/oxc · error · OxcDiagnostic

Use `namespace` instead of `module` to declare custom TypeSc

Error message

Use `namespace` instead of `module` to declare custom TypeScript modules.

What it means

Raised by typescript/prefer-namespace-keyword when a custom TypeScript module is declared with the `module` keyword (module Foo {}). Since ES modules took the `module` meaning, internal declarations must use `namespace`.

Source

Thrown at crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs:13

use oxc_ast::{AstKind, ast::TSNamespaceDeclarationKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

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

fn prefer_namespace_keyword_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use `namespace` instead of `module` to declare custom TypeScript modules.")
        .with_help("Replace `module` with `namespace` for internal declarations.")
        .with_note(
            "`module` for internal declarations is no longer supported: treat it as a hard \
             error. Expect it to become a parse error in a future version of TypeScript and Oxlint. See: \
             https://github.com/microsoft/TypeScript/issues/54500, \
             https://github.com/microsoft/TypeScript/issues/62211, \
             https://github.com/microsoft/TypeScript/pull/62876.",
        )
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// This rule reports when the module keyword is used instead of namespace.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `module` with `namespace` in the declaration.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs:13 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/8a91bd6dd2239ae1. Report an issue: GitHub.