Repository navigation
Support augmenting module with export as namespace - #27281
Merged
2 commits merged intoOct 30, 2018
Merged
2 commits merged into
2 commits merged into
Conversation
ghost
requested review from
Ryan Cavanaugh (RyanCavanaugh) and
Nathan Shively-Sanders (sandersn)
September 21, 2018 23:27
| export const conflict = 0; | ||
| } | ||
|
|
||
| a.x + a.y + a.z + a.conflict; |
There was a problem hiding this comment.
how can we access a in a module?
Contributor
There was a problem hiding this comment.
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.
I'm not convinced we need this ability. Does this PR need to exist for the declare module "./a" version to work?
Author
There was a problem hiding this comment.
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.
Nathan Shively-Sanders (sandersn)
approved these changes
Oct 30, 2018
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12106
In
getTypeOfSymbol, the cases forSymbolFlags.ValueModuleandSymbolFlags.Aliasare 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.