Skip to content

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

Merged
2 commits merged into from
Oct 30, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Sep 21, 2018

Fixes #12106

In getTypeOfSymbol, the cases for SymbolFlags.ValueModule and SymbolFlags.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 merging export as namespace a; with declare 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.

export const conflict = 0;
}

a.x + a.y + a.z + a.conflict;
Copy link
Member

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?

Copy link
Contributor

@saschanaz saschanaz Oct 27, 2018

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 {
Copy link
Member

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?

Copy link
Author

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.

@sandersn sandersn self-assigned this Oct 30, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't augment UMD namespace
2 participants