-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Less aggressive contextual signature instantiation #33228
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
4 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
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/contextualSignatureInstantiation4.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 @@ | ||
//// [contextualSignatureInstantiation4.ts] | ||
// Repros from #32976 | ||
|
||
declare class Banana<T extends string> { constructor(a: string, property: T) } | ||
|
||
declare function fruitFactory1<TFruit>(Fruit: new (...args: any[]) => TFruit): TFruit | ||
const banana1 = fruitFactory1(Banana) // Banana<any> | ||
|
||
declare function fruitFactory2<TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit): TFruit | ||
const banana2 = fruitFactory2(Banana) // Banana<any> | ||
|
||
declare function fruitFactory3<TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit): TFruit | ||
const banana3 = fruitFactory3(Banana) // Banana<"foo"> | ||
|
||
declare function fruitFactory4<TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit): TFruit | ||
const banana4 = fruitFactory4(Banana) // Banana<"foo"> | ||
|
||
declare function fruitFactory5<TFruit>(Fruit: new (...args: "foo"[]) => TFruit): TFruit | ||
const banana5 = fruitFactory5(Banana) // Banana<"foo"> | ||
|
||
|
||
//// [contextualSignatureInstantiation4.js] | ||
"use strict"; | ||
// Repros from #32976 | ||
var banana1 = fruitFactory1(Banana); // Banana<any> | ||
var banana2 = fruitFactory2(Banana); // Banana<any> | ||
var banana3 = fruitFactory3(Banana); // Banana<"foo"> | ||
var banana4 = fruitFactory4(Banana); // Banana<"foo"> | ||
var banana5 = fruitFactory5(Banana); // Banana<"foo"> |
79 changes: 79 additions & 0 deletions
79
tests/baselines/reference/contextualSignatureInstantiation4.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,79 @@ | ||
=== tests/cases/compiler/contextualSignatureInstantiation4.ts === | ||
// Repros from #32976 | ||
|
||
declare class Banana<T extends string> { constructor(a: string, property: T) } | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
>T : Symbol(T, Decl(contextualSignatureInstantiation4.ts, 2, 21)) | ||
>a : Symbol(a, Decl(contextualSignatureInstantiation4.ts, 2, 53)) | ||
>property : Symbol(property, Decl(contextualSignatureInstantiation4.ts, 2, 63)) | ||
>T : Symbol(T, Decl(contextualSignatureInstantiation4.ts, 2, 21)) | ||
|
||
declare function fruitFactory1<TFruit>(Fruit: new (...args: any[]) => TFruit): TFruit | ||
>fruitFactory1 : Symbol(fruitFactory1, Decl(contextualSignatureInstantiation4.ts, 2, 78)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 4, 31)) | ||
>Fruit : Symbol(Fruit, Decl(contextualSignatureInstantiation4.ts, 4, 39)) | ||
>args : Symbol(args, Decl(contextualSignatureInstantiation4.ts, 4, 51)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 4, 31)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 4, 31)) | ||
|
||
const banana1 = fruitFactory1(Banana) // Banana<any> | ||
>banana1 : Symbol(banana1, Decl(contextualSignatureInstantiation4.ts, 5, 5)) | ||
>fruitFactory1 : Symbol(fruitFactory1, Decl(contextualSignatureInstantiation4.ts, 2, 78)) | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
|
||
declare function fruitFactory2<TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit): TFruit | ||
>fruitFactory2 : Symbol(fruitFactory2, Decl(contextualSignatureInstantiation4.ts, 5, 37)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 7, 31)) | ||
>Fruit : Symbol(Fruit, Decl(contextualSignatureInstantiation4.ts, 7, 39)) | ||
>a : Symbol(a, Decl(contextualSignatureInstantiation4.ts, 7, 51)) | ||
>args : Symbol(args, Decl(contextualSignatureInstantiation4.ts, 7, 61)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 7, 31)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 7, 31)) | ||
|
||
const banana2 = fruitFactory2(Banana) // Banana<any> | ||
>banana2 : Symbol(banana2, Decl(contextualSignatureInstantiation4.ts, 8, 5)) | ||
>fruitFactory2 : Symbol(fruitFactory2, Decl(contextualSignatureInstantiation4.ts, 5, 37)) | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
|
||
declare function fruitFactory3<TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit): TFruit | ||
>fruitFactory3 : Symbol(fruitFactory3, Decl(contextualSignatureInstantiation4.ts, 8, 37)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 10, 31)) | ||
>Fruit : Symbol(Fruit, Decl(contextualSignatureInstantiation4.ts, 10, 39)) | ||
>a : Symbol(a, Decl(contextualSignatureInstantiation4.ts, 10, 51)) | ||
>s : Symbol(s, Decl(contextualSignatureInstantiation4.ts, 10, 61)) | ||
>args : Symbol(args, Decl(contextualSignatureInstantiation4.ts, 10, 71)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 10, 31)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 10, 31)) | ||
|
||
const banana3 = fruitFactory3(Banana) // Banana<"foo"> | ||
>banana3 : Symbol(banana3, Decl(contextualSignatureInstantiation4.ts, 11, 5)) | ||
>fruitFactory3 : Symbol(fruitFactory3, Decl(contextualSignatureInstantiation4.ts, 8, 37)) | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
|
||
declare function fruitFactory4<TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit): TFruit | ||
>fruitFactory4 : Symbol(fruitFactory4, Decl(contextualSignatureInstantiation4.ts, 11, 37)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 13, 31)) | ||
>Fruit : Symbol(Fruit, Decl(contextualSignatureInstantiation4.ts, 13, 39)) | ||
>a : Symbol(a, Decl(contextualSignatureInstantiation4.ts, 13, 51)) | ||
>args : Symbol(args, Decl(contextualSignatureInstantiation4.ts, 13, 61)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 13, 31)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 13, 31)) | ||
|
||
const banana4 = fruitFactory4(Banana) // Banana<"foo"> | ||
>banana4 : Symbol(banana4, Decl(contextualSignatureInstantiation4.ts, 14, 5)) | ||
>fruitFactory4 : Symbol(fruitFactory4, Decl(contextualSignatureInstantiation4.ts, 11, 37)) | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
|
||
declare function fruitFactory5<TFruit>(Fruit: new (...args: "foo"[]) => TFruit): TFruit | ||
>fruitFactory5 : Symbol(fruitFactory5, Decl(contextualSignatureInstantiation4.ts, 14, 37)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 16, 31)) | ||
>Fruit : Symbol(Fruit, Decl(contextualSignatureInstantiation4.ts, 16, 39)) | ||
>args : Symbol(args, Decl(contextualSignatureInstantiation4.ts, 16, 51)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 16, 31)) | ||
>TFruit : Symbol(TFruit, Decl(contextualSignatureInstantiation4.ts, 16, 31)) | ||
|
||
const banana5 = fruitFactory5(Banana) // Banana<"foo"> | ||
>banana5 : Symbol(banana5, Decl(contextualSignatureInstantiation4.ts, 17, 5)) | ||
>fruitFactory5 : Symbol(fruitFactory5, Decl(contextualSignatureInstantiation4.ts, 14, 37)) | ||
>Banana : Symbol(Banana, Decl(contextualSignatureInstantiation4.ts, 0, 0)) | ||
|
67 changes: 67 additions & 0 deletions
67
tests/baselines/reference/contextualSignatureInstantiation4.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,67 @@ | ||
=== tests/cases/compiler/contextualSignatureInstantiation4.ts === | ||
// Repros from #32976 | ||
|
||
declare class Banana<T extends string> { constructor(a: string, property: T) } | ||
>Banana : Banana<T> | ||
>a : string | ||
>property : T | ||
|
||
declare function fruitFactory1<TFruit>(Fruit: new (...args: any[]) => TFruit): TFruit | ||
>fruitFactory1 : <TFruit>(Fruit: new (...args: any[]) => TFruit) => TFruit | ||
>Fruit : new (...args: any[]) => TFruit | ||
>args : any[] | ||
|
||
const banana1 = fruitFactory1(Banana) // Banana<any> | ||
>banana1 : Banana<any> | ||
>fruitFactory1(Banana) : Banana<any> | ||
>fruitFactory1 : <TFruit>(Fruit: new (...args: any[]) => TFruit) => TFruit | ||
>Banana : typeof Banana | ||
|
||
declare function fruitFactory2<TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit): TFruit | ||
>fruitFactory2 : <TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit) => TFruit | ||
>Fruit : new (a: string, ...args: any[]) => TFruit | ||
>a : string | ||
>args : any[] | ||
|
||
const banana2 = fruitFactory2(Banana) // Banana<any> | ||
>banana2 : Banana<any> | ||
>fruitFactory2(Banana) : Banana<any> | ||
>fruitFactory2 : <TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit) => TFruit | ||
>Banana : typeof Banana | ||
|
||
declare function fruitFactory3<TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit): TFruit | ||
>fruitFactory3 : <TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit) => TFruit | ||
>Fruit : new (a: string, s: "foo", ...args: any[]) => TFruit | ||
>a : string | ||
>s : "foo" | ||
>args : any[] | ||
|
||
const banana3 = fruitFactory3(Banana) // Banana<"foo"> | ||
>banana3 : Banana<"foo"> | ||
>fruitFactory3(Banana) : Banana<"foo"> | ||
>fruitFactory3 : <TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit) => TFruit | ||
>Banana : typeof Banana | ||
|
||
declare function fruitFactory4<TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit): TFruit | ||
>fruitFactory4 : <TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit) => TFruit | ||
>Fruit : new (a: string, ...args: "foo"[]) => TFruit | ||
>a : string | ||
>args : "foo"[] | ||
|
||
const banana4 = fruitFactory4(Banana) // Banana<"foo"> | ||
>banana4 : Banana<"foo"> | ||
>fruitFactory4(Banana) : Banana<"foo"> | ||
>fruitFactory4 : <TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit) => TFruit | ||
>Banana : typeof Banana | ||
|
||
declare function fruitFactory5<TFruit>(Fruit: new (...args: "foo"[]) => TFruit): TFruit | ||
>fruitFactory5 : <TFruit>(Fruit: new (...args: "foo"[]) => TFruit) => TFruit | ||
>Fruit : new (...args: "foo"[]) => TFruit | ||
>args : "foo"[] | ||
|
||
const banana5 = fruitFactory5(Banana) // Banana<"foo"> | ||
>banana5 : Banana<"foo"> | ||
>fruitFactory5(Banana) : Banana<"foo"> | ||
>fruitFactory5 : <TFruit>(Fruit: new (...args: "foo"[]) => TFruit) => TFruit | ||
>Banana : typeof Banana | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @strict: true | ||
|
||
// Repros from #32976 | ||
|
||
declare class Banana<T extends string> { constructor(a: string, property: T) } | ||
|
||
declare function fruitFactory1<TFruit>(Fruit: new (...args: any[]) => TFruit): TFruit | ||
const banana1 = fruitFactory1(Banana) // Banana<any> | ||
|
||
declare function fruitFactory2<TFruit>(Fruit: new (a: string, ...args: any[]) => TFruit): TFruit | ||
const banana2 = fruitFactory2(Banana) // Banana<any> | ||
|
||
declare function fruitFactory3<TFruit>(Fruit: new (a: string, s: "foo", ...args: any[]) => TFruit): TFruit | ||
const banana3 = fruitFactory3(Banana) // Banana<"foo"> | ||
|
||
declare function fruitFactory4<TFruit>(Fruit: new (a: string, ...args: "foo"[]) => TFruit): TFruit | ||
const banana4 = fruitFactory4(Banana) // Banana<"foo"> | ||
|
||
declare function fruitFactory5<TFruit>(Fruit: new (...args: "foo"[]) => TFruit): TFruit | ||
const banana5 = fruitFactory5(Banana) // Banana<"foo"> |
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.
In addition to
TypeVariable
, should this also be looking forSubstitution
(since that wraps a type variable pretty directly)?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.
Can you write an example that would depend on this?
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.
still instantiates as
string
on this PR.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.
No, for your example you get what you'd expect with the PR:
The substitution type would need to be in the contextual type (i.e. the parameter's type would need to be a substitution type) for the original question you posed to make sense. I don't see how that could happen which is why I asked for an example.