-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
50 changes: 50 additions & 0 deletions
50
tests/baselines/reference/exportAsNamespace_augment.errors.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/a.d.ts(3,14): error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
/b.ts(6,22): error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
/b.ts(12,18): error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
/b.ts(15,1): error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
/b.ts(15,7): error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
/b.ts(15,13): error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
/b.ts(15,19): error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
|
||
|
||
==== /a.d.ts (1 errors) ==== | ||
export as namespace a; | ||
export const x = 0; | ||
export const conflict = 0; | ||
~~~~~~~~ | ||
!!! error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
!!! related TS6203 /b.ts:6:22: 'conflict' was also declared here. | ||
!!! related TS6204 /b.ts:6:22: and here. | ||
|
||
==== /b.ts (6 errors) ==== | ||
import * as a2 from "./a"; | ||
|
||
declare global { | ||
namespace a { | ||
export const y = 0; | ||
export const conflict = 0; | ||
~~~~~~~~ | ||
!!! error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
!!! related TS6203 /a.d.ts:3:14: 'conflict' was also declared here. | ||
} | ||
} | ||
|
||
declare module "./a" { | ||
export const z = 0; | ||
export const conflict = 0; | ||
~~~~~~~~ | ||
!!! error TS2451: Cannot redeclare block-scoped variable 'conflict'. | ||
!!! related TS6203 /a.d.ts:3:14: 'conflict' was also declared here. | ||
} | ||
|
||
a.x + a.y + a.z + a.conflict; | ||
~ | ||
!!! error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
~ | ||
!!! error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
~ | ||
!!! error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
~ | ||
!!! error TS2686: 'a' refers to a UMD global, but the current file is a module. Consider adding an import instead. | ||
a2.x + a2.y + a2.z + a2.conflict; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [tests/cases/compiler/exportAsNamespace_augment.ts] //// | ||
|
||
//// [a.d.ts] | ||
export as namespace a; | ||
export const x = 0; | ||
export const conflict = 0; | ||
|
||
//// [b.ts] | ||
import * as a2 from "./a"; | ||
|
||
declare global { | ||
namespace a { | ||
export const y = 0; | ||
export const conflict = 0; | ||
} | ||
} | ||
|
||
declare module "./a" { | ||
export const z = 0; | ||
export const conflict = 0; | ||
} | ||
|
||
a.x + a.y + a.z + a.conflict; | ||
a2.x + a2.y + a2.z + a2.conflict; | ||
|
||
|
||
//// [b.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var a2 = require("./a"); | ||
a.x + a.y + a.z + a.conflict; | ||
a2.x + a2.y + a2.z + a2.conflict; |
66 changes: 66 additions & 0 deletions
66
tests/baselines/reference/exportAsNamespace_augment.symbols
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
=== /a.d.ts === | ||
export as namespace a; | ||
>a : Symbol(a, Decl(a.d.ts, 0, 0)) | ||
|
||
export const x = 0; | ||
>x : Symbol(x, Decl(a.d.ts, 1, 12)) | ||
|
||
export const conflict = 0; | ||
>conflict : Symbol(conflict, Decl(a.d.ts, 2, 12)) | ||
|
||
=== /b.ts === | ||
import * as a2 from "./a"; | ||
>a2 : Symbol(a2, Decl(b.ts, 0, 6)) | ||
|
||
declare global { | ||
>global : Symbol(global, Decl(b.ts, 0, 26)) | ||
|
||
namespace a { | ||
>a : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
|
||
export const y = 0; | ||
>y : Symbol(y, Decl(b.ts, 4, 20)) | ||
|
||
export const conflict = 0; | ||
>conflict : Symbol(conflict, Decl(b.ts, 5, 20)) | ||
} | ||
} | ||
|
||
declare module "./a" { | ||
>"./a" : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
|
||
export const z = 0; | ||
>z : Symbol(z, Decl(b.ts, 10, 16)) | ||
|
||
export const conflict = 0; | ||
>conflict : Symbol(conflict, Decl(b.ts, 11, 16)) | ||
} | ||
|
||
a.x + a.y + a.z + a.conflict; | ||
>a.x : Symbol(a2.x, Decl(a.d.ts, 1, 12)) | ||
>a : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
>x : Symbol(a2.x, Decl(a.d.ts, 1, 12)) | ||
>a.y : Symbol(a2.y, Decl(b.ts, 4, 20)) | ||
>a : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
>y : Symbol(a2.y, Decl(b.ts, 4, 20)) | ||
>a.z : Symbol(a2.z, Decl(b.ts, 10, 16)) | ||
>a : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
>z : Symbol(a2.z, Decl(b.ts, 10, 16)) | ||
>a.conflict : Symbol(a2.conflict, Decl(a.d.ts, 2, 12)) | ||
>a : Symbol(a2, Decl(a.d.ts, 0, 0), Decl(b.ts, 2, 16), Decl(b.ts, 7, 1)) | ||
>conflict : Symbol(a2.conflict, Decl(a.d.ts, 2, 12)) | ||
|
||
a2.x + a2.y + a2.z + a2.conflict; | ||
>a2.x : Symbol(a2.x, Decl(a.d.ts, 1, 12)) | ||
>a2 : Symbol(a2, Decl(b.ts, 0, 6)) | ||
>x : Symbol(a2.x, Decl(a.d.ts, 1, 12)) | ||
>a2.y : Symbol(a2.y, Decl(b.ts, 4, 20)) | ||
>a2 : Symbol(a2, Decl(b.ts, 0, 6)) | ||
>y : Symbol(a2.y, Decl(b.ts, 4, 20)) | ||
>a2.z : Symbol(a2.z, Decl(b.ts, 10, 16)) | ||
>a2 : Symbol(a2, Decl(b.ts, 0, 6)) | ||
>z : Symbol(a2.z, Decl(b.ts, 10, 16)) | ||
>a2.conflict : Symbol(a2.conflict, Decl(a.d.ts, 2, 12)) | ||
>a2 : Symbol(a2, Decl(b.ts, 0, 6)) | ||
>conflict : Symbol(a2.conflict, Decl(a.d.ts, 2, 12)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
=== /a.d.ts === | ||
export as namespace a; | ||
>a : typeof import("/a") | ||
|
||
export const x = 0; | ||
>x : 0 | ||
>0 : 0 | ||
|
||
export const conflict = 0; | ||
>conflict : 0 | ||
>0 : 0 | ||
|
||
=== /b.ts === | ||
import * as a2 from "./a"; | ||
>a2 : typeof a2 | ||
|
||
declare global { | ||
>global : typeof global | ||
|
||
namespace a { | ||
>a : typeof a2 | ||
|
||
export const y = 0; | ||
>y : 0 | ||
>0 : 0 | ||
|
||
export const conflict = 0; | ||
>conflict : 0 | ||
>0 : 0 | ||
} | ||
} | ||
|
||
declare module "./a" { | ||
>"./a" : typeof a2 | ||
|
||
export const z = 0; | ||
>z : 0 | ||
>0 : 0 | ||
|
||
export const conflict = 0; | ||
>conflict : 0 | ||
>0 : 0 | ||
} | ||
|
||
a.x + a.y + a.z + a.conflict; | ||
>a.x + a.y + a.z + a.conflict : number | ||
>a.x + a.y + a.z : number | ||
>a.x + a.y : number | ||
>a.x : 0 | ||
>a : typeof a2 | ||
>x : 0 | ||
>a.y : 0 | ||
>a : typeof a2 | ||
>y : 0 | ||
>a.z : 0 | ||
>a : typeof a2 | ||
>z : 0 | ||
>a.conflict : 0 | ||
>a : typeof a2 | ||
>conflict : 0 | ||
|
||
a2.x + a2.y + a2.z + a2.conflict; | ||
>a2.x + a2.y + a2.z + a2.conflict : number | ||
>a2.x + a2.y + a2.z : number | ||
>a2.x + a2.y : number | ||
>a2.x : 0 | ||
>a2 : typeof a2 | ||
>x : 0 | ||
>a2.y : 0 | ||
>a2 : typeof a2 | ||
>y : 0 | ||
>a2.z : 0 | ||
>a2 : typeof a2 | ||
>z : 0 | ||
>a2.conflict : 0 | ||
>a2 : typeof a2 | ||
>conflict : 0 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @Filename: /a.d.ts | ||
export as namespace a; | ||
export const x = 0; | ||
export const conflict = 0; | ||
|
||
// @Filename: /b.ts | ||
import * as a2 from "./a"; | ||
|
||
declare global { | ||
namespace a { | ||
export const y = 0; | ||
export const conflict = 0; | ||
} | ||
} | ||
|
||
declare module "./a" { | ||
export const z = 0; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. how can we access There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
a2.x + a2.y + a2.z + a2.conflict; |
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.
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
b.ts
c.ts
It will fail in
c.ts
. But there is no failure forimport { y } from "./a";
-- the module got augmented but the namespace didn't.