You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript supports the module keyword for namespaces (from when they were originally called "internal modules").
module foo{// ...}// is equivalent tonamespacefoo{// ...}
It was confusing always clarifying "internal module" vs "external module", so we introduced the namespace keyword back in TS 1.5 (Namespace keyword #2159). Intent was to phase out usage of module outside of declare module "...".
Now TC39 has two proposals that want to use the module keyword.
The module expressions proposal don't have any conflict, but are confusing if TypeScript's namespaces can still use module.
The module declarations proposal creates a conflict.
We don't necessarily want the module declaration proposal, but it does raise the question: what do we want for the module long-term? We want to ask this question regardless of these proposals.
Do we want to deprecate or remove support for the module keyword when used for namespaces?
Feels like it's time to retire the module keyword for these - but geez there's a lot of code that already uses the module keyword for namespaces when we do a casual code search.
Well a lot of these search hits are TypeScript itself, tests for supporting TypeScript (e.g. in Prettier), or really old code whose status we can't really evaluate.
Coming back to the proposal - it would be bad if module started to mean a new thing. If you look at a TypeScript file, you won't know if the syntax refers to a TypeScript "internal module"/namespace, or if it refers to the new ECMAScript thing.
We have reservations regarding that (plus questions about the cost/benefit of this feature).
Really don't want to spend time on the semantics of the proposal though.
So what's deprecation vs. removal imply?
Deprecation means we have until 5.5 to remove, but users can use deprecation opt-out.
Removal means that we would...still gracefully parse, but give an error. Then one day make it mean something else if module expression/declarations ever proceeded to ECMAScript.
We feel okay about deprecation. Deprecation means we have a pretty good window of opportunity to change our mind. It also allows people to get the signal "hey, stop using the module keyword for namespaces".
Plus we could have quick fixes and it's easy enough to write a find/replace regex.
Find:
(\s*(?:declare )?)module (\w+(?:\.\w+)*\s*\{)
Replace:
$1namespace $2
or
\1namespace \2
Probably covers 99% of code, the rest is manually correctable.
[[EDITOR'S NOTE]]: we are not talking about deprecating module used like this:
// This is fine!
module "foo"{// <- notice the quotes!// ...}
We are talking about deprecating module used like this
module foo{// <- notice this is just an identifier// ...}
in which any existing code would need to be rewritten to use namespace.
// This is fine!namespacefoo{// ...}
The text was updated successfully, but these errors were encountered:
extends
as an Array intsconfig.json
#29118
tsconfig.json
s, you have to have them extend linearly, know about each outer.b
extendsa
, andc
extendsb
.{ ...a, ...b, ...c, /* inline options */ }
).isolatedModules
on Global/Script Files#46295
#51479
verbatimModuleSyntax
, we realized it's a subset(?)/superset(?) ofisolatedModules
isolatedModules
: every file needs to be a module.namespace
s.isolatedModules
expecting only modules, we disallow certain kinds of declarations likenamespace
s in the global scope.enum
s have the same issue.--isolatedModules
is enabled]].moduleDetection: force
?enum
snamespace
sdecorator metadata (already banned in
isolatedModules
)static
block in a class that merges with a namespace???verbatimModuleSyntax
(Proposal: deprecateimportsNotUsedAsValues
andpreserveValueImports
in favor of single flag #51479) should be a superset.isolatedModules
and some extra stuff.Deprecating the
module
Keyword From Namespace Declarationshttps://github.com/tc39/proposal-module-expressions
https://github.com/tc39/proposal-module-declarations
TypeScript supports the
module
keyword for namespaces (from when they were originally called "internal modules").namespace
keyword back in TS 1.5 (Namespace keyword #2159). Intent was to phase out usage ofmodule
outside ofdeclare module "..."
.Now TC39 has two proposals that want to use the
module
keyword.module
.We don't necessarily want the module declaration proposal, but it does raise the question: what do we want for the
module
long-term? We want to ask this question regardless of these proposals.Do we want to deprecate or remove support for the
module
keyword when used for namespaces?Feels like it's time to retire the
module
keyword for these - but geez there's a lot of code that already uses themodule
keyword fornamespace
s when we do a casual code search.Coming back to the proposal - it would be bad if
module
started to mean a new thing. If you look at a TypeScript file, you won't know if the syntax refers to a TypeScript "internal module"/namespace, or if it refers to the new ECMAScript thing.So what's deprecation vs. removal imply?
module
expression/declarations ever proceeded to ECMAScript.We feel okay about deprecation. Deprecation means we have a pretty good window of opportunity to change our mind. It also allows people to get the signal "hey, stop using the
module
keyword for namespaces".Plus we could have quick fixes and it's easy enough to write a find/replace regex.
Find:
Replace:
or
\1namespace \2
[[EDITOR'S NOTE]]: we are not talking about deprecating
module
used like this:We are talking about deprecating
module
used like thisin which any existing code would need to be rewritten to use
namespace
.The text was updated successfully, but these errors were encountered: