-
Notifications
You must be signed in to change notification settings - Fork 893
Fix dts emit for type params for object methods in const context #3265
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
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
29 changes: 29 additions & 0 deletions
29
testdata/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.js
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,29 @@ | ||
| //// [tests/cases/compiler/declarationEmitConstObjectLiteralGenericMethod1.ts] //// | ||
|
|
||
| //// [declarationEmitConstObjectLiteralGenericMethod1.ts] | ||
| export const obj1 = { | ||
| id<T>(value: T) { | ||
| return value; | ||
| }, | ||
| pair<T>(left: T, right: T) { | ||
| return [left, right]; | ||
| }, | ||
| } as const; | ||
|
|
||
|
|
||
| //// [declarationEmitConstObjectLiteralGenericMethod1.js] | ||
| export const obj1 = { | ||
| id(value) { | ||
| return value; | ||
| }, | ||
| pair(left, right) { | ||
| return [left, right]; | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| //// [declarationEmitConstObjectLiteralGenericMethod1.d.ts] | ||
| export declare const obj1: { | ||
| id<T>(value: T): T; | ||
| pair<T_1>(left: T_1, right: T_1): T_1[]; | ||
| }; |
32 changes: 32 additions & 0 deletions
32
...data/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.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,32 @@ | ||
| //// [tests/cases/compiler/declarationEmitConstObjectLiteralGenericMethod1.ts] //// | ||
|
|
||
| === declarationEmitConstObjectLiteralGenericMethod1.ts === | ||
| export const obj1 = { | ||
| >obj1 : Symbol(obj1, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 0, 12)) | ||
|
|
||
| id<T>(value: T) { | ||
| >id : Symbol(id, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 0, 21)) | ||
| >T : Symbol(T, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 1, 7)) | ||
| >value : Symbol(value, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 1, 10)) | ||
| >T : Symbol(T, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 1, 7)) | ||
|
|
||
| return value; | ||
| >value : Symbol(value, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 1, 10)) | ||
|
|
||
| }, | ||
| pair<T>(left: T, right: T) { | ||
| >pair : Symbol(pair, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 3, 6)) | ||
| >T : Symbol(T, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 9)) | ||
| >left : Symbol(left, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 12)) | ||
| >T : Symbol(T, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 9)) | ||
| >right : Symbol(right, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 20)) | ||
| >T : Symbol(T, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 9)) | ||
|
|
||
| return [left, right]; | ||
| >left : Symbol(left, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 12)) | ||
| >right : Symbol(right, Decl(declarationEmitConstObjectLiteralGenericMethod1.ts, 4, 20)) | ||
|
|
||
| }, | ||
| } as const; | ||
| >const : Symbol(const) | ||
|
|
29 changes: 29 additions & 0 deletions
29
testdata/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.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,29 @@ | ||
| //// [tests/cases/compiler/declarationEmitConstObjectLiteralGenericMethod1.ts] //// | ||
|
|
||
| === declarationEmitConstObjectLiteralGenericMethod1.ts === | ||
| export const obj1 = { | ||
| >obj1 : { readonly id: <T>(value: T) => T; readonly pair: <T>(left: T, right: T) => T[]; } | ||
| >{ id<T>(value: T) { return value; }, pair<T>(left: T, right: T) { return [left, right]; },} as const : { readonly id: <T>(value: T) => T; readonly pair: <T>(left: T, right: T) => T[]; } | ||
| >{ id<T>(value: T) { return value; }, pair<T>(left: T, right: T) { return [left, right]; },} : { readonly id: <T>(value: T) => T; readonly pair: <T>(left: T, right: T) => T[]; } | ||
|
|
||
| id<T>(value: T) { | ||
| >id : <T>(value: T) => T | ||
| >value : T | ||
|
|
||
| return value; | ||
| >value : T | ||
|
|
||
| }, | ||
| pair<T>(left: T, right: T) { | ||
| >pair : <T>(left: T, right: T) => T[] | ||
| >left : T | ||
| >right : T | ||
|
|
||
| return [left, right]; | ||
| >[left, right] : T[] | ||
| >left : T | ||
| >right : T | ||
|
|
||
| }, | ||
| } as const; | ||
|
|
10 changes: 10 additions & 0 deletions
10
testdata/tests/cases/compiler/declarationEmitConstObjectLiteralGenericMethod1.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 @@ | ||
| // @declaration: true | ||
|
|
||
| export const obj1 = { | ||
| id<T>(value: T) { | ||
| return value; | ||
| }, | ||
| pair<T>(left: T, right: T) { | ||
| return [left, right]; | ||
| }, | ||
| } as const; |
Oops, something went wrong.
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 was suspicious of this, but it's the same thing we do for
pseudochecker.PseudoTypeKindSingleCallSignaturejust above here.I do wonder what would happen if you had a type parameter that say
extends typeof local. Do we handle that in general?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.
Yeah, that's handled in general - unless you have some specific weird edge in mind that could break things with ID or without it.
typeof xis nice because it has to refer to an existing entity name and the declaration emitter also preserves the referenced name (and emits its type ofc) when needed even if that name is not exported otherwise. Local-local names in closures are usually just replaced with their types. In ID it's also kinda hard to even somehow try to "leak" a local-local to the top-level scope because of: