Skip to content

Support augmenting module with export as namespace - #27281

Merged
2 commits merged into
masterfrom
exportAsNamespace_augment
Oct 30, 2018
Merged

2 commits merged into
masterfrom
exportAsNamespace_augment

Conversation

@ghost

@ghost Deleted user (ghost) commented Sep 21, 2018 •

Copy link
Copy Markdown

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
Copy Markdown
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?

@saschanaz Kagami Sascha Rosylight (saschanaz) Oct 27, 2018 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't augment UMD namespace

2 participants