-
Notifications
You must be signed in to change notification settings - Fork 12.9k
use default type parameter rather than unknown
when show quick help
#46792
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
35 changes: 28 additions & 7 deletions
35
tests/cases/fourslash/signatureHelpExplicitTypeArguments.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 |
---|---|---|
@@ -1,16 +1,37 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
////declare function f<T = boolean, U = string>(x: T, y: U): T; | ||
////f<number, string>(/*1*/); | ||
////f(/*2*/); | ||
////f<number>(/*3*/); | ||
////f<number, string, boolean>(/*4*/); | ||
//// declare function f<T = boolean, U = string>(x: T, y: U): T; | ||
//// f<number, string>(/*1*/); | ||
//// f(/*2*/); | ||
//// f<number>(/*3*/); | ||
//// f<number, string, boolean>(/*4*/); | ||
|
||
//// interface A { a: number } | ||
//// interface B extends A { b: string } | ||
//// declare function g<T, U, V extends A = B>(x: T, y: U, z: V): T; | ||
//// declare function h<T, U, V extends A>(x: T, y: U, z: V): T; | ||
//// declare function j<T, U, V = B>(x: T, y: U, z: V): T; | ||
//// g(/*5*/); | ||
//// h(/*6*/); | ||
//// j(/*7*/); | ||
//// g<number>(/*8*/); | ||
//// h<number>(/*9*/); | ||
//// j<number>(/*10*/); | ||
|
||
verify.signatureHelp( | ||
{ marker: "1", text: "f(x: number, y: string): number" }, | ||
{ marker: "2", text: "f(x: boolean, y: string): boolean" }, | ||
// too few -- fill in rest with unknown | ||
{ marker: "3", text: "f(x: number, y: unknown): number" }, | ||
// too few -- fill in rest with default | ||
{ marker: "3", text: "f(x: number, y: string): number" }, | ||
// too many -- ignore extra type arguments | ||
{ marker: "4", text: "f(x: number, y: string): number" }, | ||
|
||
// not matched signature and no type arguments | ||
{ marker: "5", text: "g(x: unknown, y: unknown, z: B): unknown" }, | ||
{ marker: "6", text: "h(x: unknown, y: unknown, z: A): unknown" }, | ||
{ marker: "7", text: "j(x: unknown, y: unknown, z: B): unknown" }, | ||
// not matched signature and too few type arguments | ||
{ marker: "8", text: "g(x: number, y: unknown, z: B): number" }, | ||
{ marker: "9", text: "h(x: number, y: unknown, z: A): number" }, | ||
{ marker: "10", text: "j(x: number, y: unknown, z: B): number" }, | ||
); |
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 what cases does this loop still run?
Uh oh!
There was an error while loading. Please reload this page.
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.
like this(the example is from
instantiateGenericClassWithWrongNumberOfTypeArguments.ts
):fillMissingTypeArguments
only fillstypeArgument
when there are valid default type parameter, which means the number of typeArgument is betweenminTypeParameterCount
andtypeParameterCount
. It does not always fill the type argument to full.Uh oh!
There was an error while loading. Please reload this page.
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.
And, we would better to mention this case:
However, it is a little different: there is an error on the number of type arguments. So I feel that both methods are OK? Or the default type parameter is better than constraint?
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.
Hm, I feel like using the default here makes a little more sense, but I don’t know that it’s super critical since it’s an error anyway.
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.
Now prefer default type parameter than constraint for quick info. Correspond tests are added.
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.
It should be noted that this change doesn’t just affect quick info; it actually affects the type instantiated in these kinds of error scenarios. I’m surprised there weren’t any existing baselines that needed updating. In your example above, you can check the type of
d.z
and see that in main, the type isA
, and this branch, the type isB
.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.
The new behavior is more intuitive to me, but others should weigh in. The most conservative thing would be to leave it as it was, against my earlier advice.
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.
Thanks for pointing it out, I did not notice it! This does make sense. And, I am surprised too :)
But do we really need to revert to last commit? For:
Again, I feel both methods are OK. The final decision is up to you~