Skip to content

Suggestion: deprecate module keyword in place of namespace #23684

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
aaronbeall opened this issue Apr 25, 2018 · 1 comment
Closed

Suggestion: deprecate module keyword in place of namespace #23684

aaronbeall opened this issue Apr 25, 2018 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@aaronbeall
Copy link

aaronbeall commented Apr 25, 2018

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms: module, namespace, module vs namespace, module keyword

Suggestion:

The use of the module keyword has been replaced with namespace, except when actually declaring ES6 modules in a declaration file. However, in my personal experience I still see new developers getting confused about ES6 modules and the TS module keyword, even through it's well documented, because TS silently supports the module keyword for backwards compatibility.

Why not deprecate the use of the module keyword where it "shouldn't" be used anymore? Emit an error or a warning by default, suppressible with a tsconfig flag for backwards compatibility?

Code

// Example of needless namespacing
export module Shapes {
    export class Circle { }
    export class Square { }
}

Expected behavior:

Some kind of warning that module here should be namespace, and that a namespace is not needed in an ES6 module using export.

I realize you could argue a linter is a better place to provide this kind of check, but the idea is to help users during the learning process who will easily fall into the confusion of module as a namespace vs ES6 module.

Actual behavior:

Playground Link:

Related Issues:

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Apr 25, 2018
@RyanCavanaugh
Copy link
Member

Tracking at #51825

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants