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

noImplicitAny as suggestion #27693

Merged
merged 5 commits into from Oct 11, 2018
Merged

noImplicitAny as suggestion #27693

merged 5 commits into from Oct 11, 2018

Conversation

sandersn
Copy link
Member

With noImplicitAny suggestions, people will see suggestions for the infer-from-usage codefix even with noImplicitAny turned off. This applies to JS users, who are otherwise unlikely to see that codefix.

Notes:

  1. I want to evaluate performance before merging this.

  2. I want to make sure the suggestions are mostly reliable and sensical before merging as well. I'm going to look over our user tests.

  3. Not all noImplicitAny errors turn into suggestions. In
    particular:

    1. reportErrorsFromWidening does not, because it doesn't log an error that infer-from-usage fixes, and fixing it would require otherwise-unnecessary code.
    2. auto types do not have implicit any suggestions, because that would require running control flow in noImplicitAny mode.

Note that not all noImplicitAny errors turn into suggestions. In
particular,

1. reportErrorsFromWidening does not, because it doesn't log an error
that infer-from-usage fixes, and fixing it would require
otherwise-unnecessary code.
2. auto types do not have implicit any suggestions, because that would
require running control flow in noImplicitAny mode.
@sandersn sandersn requested a review from a user October 10, 2018 22:31
@@ -13270,7 +13264,7 @@ namespace ts {
return errorReported;
}

function reportImplicitAnyError(declaration: Declaration, type: Type) {
function reportImplicitAnyError(noImplicitAny: boolean, declaration: Declaration, type: Type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be rename this to reportImplicitAnyErrorOrSuggestion instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to take noImplicitAny as a parameter since that's already in scope. In every instance of calling this the argument is noImplicitAny; in one case the argument is true but it's within if (noImplicitAny).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to shorten it to reportImplicitAny

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andy-ms good catch. I'll get rid of the parameter.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good.
I'm thinking we should avoid reporting these even as suggestions in JS code that doesn't show an intent to be typed, i.e. doesn't use any types in its jsdoc.

@sandersn
Copy link
Member Author

@andy-ms I discussed this with @DanielRosenwasser and we decided that, for now, the easiest and strongest signal of intent is --checkJS or // @ts-check. Once I improve the infer-from-usage inferences, I think we can re-evaluate showing suggestions for all other JS users.

In JS, you only get implicit any errors/suggestions with checkJS or
ts-check turned on.
const typeAsString = typeToString(getWidenedType(type));
if (isInJSFile(declaration) && !getSourceFileOfNode(declaration).pragmas.has("checkJSDirective") && !compilerOptions.checkJs) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even get here without checkJS? Also, this must be duplicate code of something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, allowJS reports errors as usual, but doesn't actually display them.
  2. Yes, isCheckJsEnabledForFile.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, why go out of our way to not report this error, if no errors will be shown anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions will still be shown, since they're stored in a separate array, and errorOrSuggestion at the bottom of the function will create a suggestion instead of an error in an allowJs file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandersn
Copy link
Member Author

Performance seems fine. I tried on webpack, which is a big project that has tons of implicit anys intermixed with existing jsdoc. I'm pretty sure the codefix calculations are correctly deferred to when the lightbulb is clicked.

@sandersn sandersn merged commit ec0e8cb into master Oct 11, 2018
@sandersn sandersn deleted the noImplicitAny-as-suggestion branch October 11, 2018 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants