-
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
Conversation
while (typeArguments.length > typeParameters.length) { | ||
typeArguments.pop(); | ||
} | ||
typeArguments = fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), isJs); | ||
while (typeArguments.length < typeParameters.length) { |
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?
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
):
class D<T, U> {
x: T
y: U
}
var d = new D<number>();
// when hover on `d`, it shows `var d: D<number, unknown>`
// ^^^^^^ here is added by this loop, and if `U` has a constraint, it would be the constraint.
fillMissingTypeArguments
only fills typeArgument
when there are valid default type parameter, which means the number of typeArgument is between minTypeParameterCount
and typeParameterCount
. It does not always fill the type argument to full.
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:
interface A { a: number }
interface B extends A { b: string }
class D<T, U, V extends A = B> {
x: T
y: U
z: V
}
var d = new D<number>();
// when hover on `d`, it shows `var d: D<number, unknown, A>`
// `A` is its constraint rather than the default type parameter `B`, this PR does not change this behavior now
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 is A
, and this branch, the type is B
.
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:
- we are doing things in the right way
- anyway, it is just an error condition which finally need be fixed by user
Again, I feel both methods are OK. The final decision is up to you~
@typescript-bot pack this |
Heya @andrewbranch, I've started to run the tarball bundle task on this PR at a0aa803. You can monitor the build here. |
npm died 😦 @typescript-bot pack this |
Heya @andrewbranch, I've started to run the tarball bundle task on this PR at a0aa803. You can monitor the build here. |
@typescript-bot pack this please |
Heya @andrewbranch, I've started to run the tarball bundle task on this PR at a0aa803. You can monitor the build here. |
Hey @andrewbranch, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
…microsoft#46792) * use default type parameter rather than `unknown` when show quick help * prefer default type parameter than constraint for quick info
Fixes #46774