-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Support augmenting module with export as namespace
#27281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
export const conflict = 0; | ||
} | ||
|
||
a.x + a.y + a.z + a.conflict; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can we access a
in a module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a
is a global namespace (because of declare global
at line 9-14), so IMO no issue.
import * as a2 from "./a"; | ||
|
||
declare global { | ||
namespace a { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced we need this ability. Does this PR need to exist for the declare module "./a"
version to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, if you have:
a.d.ts
export const x = 0;
export as namespace a;
b.ts
export {};
declare module "./a" {
export const y = 0;
}
c.ts
a.y;
It will fail in c.ts
. But there is no failure for import { y } from "./a";
-- the module got augmented but the namespace didn't.
Fixes #12106
In
getTypeOfSymbol
, the cases forSymbolFlags.ValueModule
andSymbolFlags.Alias
are separate. We're effectively treating a flags enum (where multiple flags could be set at the same time) as a regular enum (where only one member can be set). The problem is that when mergingexport as namespace a;
withdeclare namespace a {}
, we're merging an alias with a module.The solution here is to resolve the alias before merging, so we're directly merging into module "a" -- this means that regular imports from the module will be affected by the augmentation too and not just namespace uses, which I think is good.