-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Always instantiate the extends clause, even in the presence of an error #20232
Always instantiate the extends clause, even in the presence of an error #20232
Conversation
…s, instead of returning unknownType
@@ -6705,7 +6705,7 @@ namespace ts { | |||
const numTypeParameters = length(typeParameters); | |||
if (numTypeParameters) { | |||
const numTypeArguments = length(typeArguments); | |||
if ((isJavaScriptImplicitAny || numTypeArguments >= minTypeArgumentCount) && numTypeArguments <= numTypeParameters) { | |||
if (isJavaScriptImplicitAny || (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters)) { |
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.
we should change the name of this parameter now to be just isJavaScript
@mhegazy Can I get a rereview? I've had to update the code (since apparently I did have failing tests, I was rerunning the same old file because vscode wasn't actually saving my checker.ts buffer to disk until I went to close the file... but that's another story) to 1. only affect JS (for now), and 2. handle extraneous type arguments more gracefully (ie, not crash or produce follow-on errors). |
@@ -7195,12 +7196,15 @@ namespace ts { | |||
: Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments; | |||
const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType); | |||
error(node, diag, typeStr, minTypeArgumentCount, typeParameters.length); | |||
return unknownType; | |||
if (!isJs) { |
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.
so what broke with the permissive behavior in TS?
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.
Nothing is "broken" once all the arity-based signature removals are excised and arity verification is moved into fillMissingTypeArguments
- just observable behavior changes to follow-on error scenarios (which cause a bunch of baseline churn - and in TS it is not uniformly better behavior, since we fill with {}
instead of any
- we could change that if there's an arity mismatch); I'll open a PR on my PR to show you, here: weswigham#2
I can merge it into this PR and iterate on it if you think it's a good idea (or do a second PR after this one). I just didn't want to add it in (it is more complicated, but also likely more complete) without mentioning it to someone first. It just amounts to better error recovery, so even if it does change a bunch of any
's to more specific types in the baselines (as expected), I don't think it'd even be a breaking change, actually.
...That did take longer than I expected to fully flesh out, though - partially because I had to work around our inconsistent handling of generics on psuedoconstructors (like ArrayConstructor
). Namely you can write:
interface BadBehavingCtor {
new <T>(x: T): number;
new <T, U>(x: T, y: U): string;
}
and those ctor return types are in no way compatable, but we don't issue an error because we don't look at the different arities' signatures simultaneously right now. It's the reason for all the complexity around getInstantiatedConstructorsForTypeArguments
.
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 the clarification. i think i understand now. i am not sure i understand the change in weswigham#2, but we should talk about that one on Monday.
@weswigham let's get this in and get folks to test it, we can look at weswigham#2 in more details later on. |
Alright |
This prevents extra downstream errors from polluting the output in
checkJs
, and also leaves the component as flexibly consumable inallowJs
.