Skip to content
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

Merged

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Nov 22, 2017

This prevents extra downstream errors from polluting the output in checkJs, and also leaves the component as flexibly consumable in allowJs.

@weswigham weswigham changed the title Instantiate the extends clause even when theres a noimplicitany error in js Always instantiate the extends clause, even in the presence of an error Nov 22, 2017
@@ -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)) {
Copy link
Contributor

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

@weswigham
Copy link
Member Author

@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) {
Copy link
Contributor

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?

Copy link
Member Author

@weswigham weswigham Nov 23, 2017

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.

Copy link
Contributor

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.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 2, 2017

@weswigham let's get this in and get folks to test it, we can look at weswigham#2 in more details later on.

@weswigham
Copy link
Member Author

Alright

@weswigham weswigham merged commit 1045d95 into microsoft:master Dec 2, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants