TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Deprecate, remove support for using `module` in place of `namespace`

Open DanielRosenwasser opened this issue 4 months ago • 3 comments

In TypeScript 1.5, we introduced the namespace keyword so people could stop distinguishing between "internal modules" and "external modules". This allowed developers to more clearly say

  • "namespaces" in place of "internal modules", and
  • "modules" in place of "external modules"/"ECMAScript or CommonJS modules".

In general, we think namespaces should be used sparingly (instead just using modules when needed); however, we really don't want anyone using the module keyword anymore for them. This is for a few reasons:

  • We've had a perfectly good, clearer alternative keyword for over 10 years now
  • We may want to use the module keyword down the line in JavaScript itself

In recent years, our language service started the module keyword with a deprecation diagnostic. In editors like VS Code, this shows up as a strikethrough:

Image

We have also ensured that DefinitelyTyped is clear of the module keyword for any namespace declarations, so no @types package published in the last two years has leveraged the legacy syntax.

But now in TypeScript 6.0, we will deprecate the usage of the module keyword for namespaces. If a namespace is declared with the module keyword, TypeScript will issue an error that can only be suppressed via ignoreDeprecations. TypeScript 7.0 will always error on its usage.

These errors will apply to all locations - using the module keyword for namespaces will be an error even in declaration files (.d.ts files). If these declaration files come from an external source like on npm, we would encourage either upgrading your dependencies, forking them, or using a solution like patch-package.

See more on deprecations/behavior changes in 6.0 at #54500.

DanielRosenwasser avatar Aug 05 '25 17:08 DanielRosenwasser

If/when the module keyword comes into use by ECMAScript, do we know how we'll distinguish them in d.ts files?

jakebailey avatar Aug 05 '25 21:08 jakebailey

I think the only plan at this point (or which I can think of) would be we just assume whatever new meaning module has. Users would have to force a reinterpretation with patch-package or something.

DanielRosenwasser avatar Aug 05 '25 22:08 DanielRosenwasser