-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix merging of JS value & TS type decl #38936
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
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
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.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,19 @@ | ||
=== /x.js === | ||
module.exports.x = 1; | ||
>module.exports.x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) | ||
>module.exports : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) | ||
>module : Symbol(module, Decl(x.js, 0, 0)) | ||
>exports : Symbol("/x", Decl(x.js, 0, 0)) | ||
>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) | ||
|
||
module.exports = require("./y.js"); | ||
>module.exports : Symbol("/x", Decl(x.js, 0, 0)) | ||
>module : Symbol(export=, Decl(x.js, 0, 21)) | ||
>exports : Symbol(export=, Decl(x.js, 0, 21)) | ||
>require : Symbol(require) | ||
>"./y.js" : Symbol("/y", Decl(y.d.ts, 0, 0)) | ||
|
||
=== /y.d.ts === | ||
export declare type x = 1; | ||
>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) | ||
|
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.types
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,23 @@ | ||
=== /x.js === | ||
module.exports.x = 1; | ||
>module.exports.x = 1 : 1 | ||
>module.exports.x : number | ||
>module.exports : typeof import("/y") | ||
>module : { "\"/x\"": typeof import("/y"); } | ||
>exports : typeof import("/y") | ||
>x : number | ||
>1 : 1 | ||
|
||
module.exports = require("./y.js"); | ||
>module.exports = require("./y.js") : typeof import("/y") | ||
>module.exports : typeof import("/y") | ||
>module : { "\"/x\"": typeof import("/y"); } | ||
>exports : typeof import("/y") | ||
>require("./y.js") : typeof import("/y") | ||
>require : any | ||
>"./y.js" : "./y.js" | ||
|
||
=== /y.d.ts === | ||
export declare type x = 1; | ||
>x : 1 | ||
|
10 changes: 10 additions & 0 deletions
10
tests/cases/compiler/jsExportMemberMergedWithModuleAugmentation3.ts
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,10 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @Filename: /x.js | ||
module.exports.x = 1; | ||
module.exports = require("./y.js"); | ||
|
||
// @Filename: /y.d.ts | ||
export declare type x = 1; |
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.
@weswigham @sandersn when I was looking at this with Eli, this brought up a question as to why/how
exportedType
(defined a few lines above—the type ofrequire('./y.js')
in the test case) could have non-value members. InresolveAnonymousTypeMembers
, it copies the exports of the symbol to the type, but of course, theexports
of the .d.ts module includes a type symbol. It was surprising to me thatresolveStructuredTypeMembers
can return an anonymous object type that has members that are also types. Is that normal?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.
normal-ish -- it can easily happen when you merge a type-only namespace with an object literal:
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 realized I was confusing anonymous type members with anonymous type properties, which are guaranteed to be values. With that confusion cleared up, this fix definitely looks correct. The possibility of type members was simply overlooked in the past.