Skip to content

Always instantiate the extends clause, even in the presence of an error - #20232

Merged
Wesley Wigham (weswigham) merged 3 commits into
microsoft:masterfrom
weswigham:implicit-any-no-downstream-errors
Dec 2, 2017
Merged

Wesley Wigham (weswigham) merged 3 commits into
microsoft:masterfrom
weswigham:implicit-any-no-downstream-errors

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Nov 22, 2017 •

Copy link
Copy Markdown
Member

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

@weswigham Wesley Wigham (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
Comment thread src/compiler/checker.ts
if (numTypeParameters) {
const numTypeArguments = length(typeArguments);
if ((isJavaScriptImplicitAny || numTypeArguments >= minTypeArgumentCount) && numTypeArguments <= numTypeParameters) {
if (isJavaScriptImplicitAny || (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters)) {

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Mohamed Hegazy (@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).

Comment thread src/compiler/checker.ts
const typeStr = typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType);
error(node, diag, typeStr, minTypeArgumentCount, typeParameters.length);
return unknownType;
if (!isJs) {

Copy link
Copy Markdown
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?

@weswigham Wesley Wigham (weswigham) Nov 23, 2017 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
Contributor

Wesley Wigham (@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
Copy Markdown
Member Author

Alright

@weswigham
Wesley Wigham (weswigham) merged commit 1045d95 into microsoft:master Dec 2, 2017
@microsoft 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