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

infer-from-usage suggestions can't be ignored, and always do something when invoked. #28206

Merged
merged 4 commits into from
Oct 29, 2018

Conversation

sandersn
Copy link
Member

  1. Always infer any when no types can be inferred.
  2. The ts-ignore codefix does not apply to infer-from-usage.

The ts-ignore codefix does not apply to suggestions, so I made separate implicit any suggestions.

Based on our discussion with VS Code, and with @bterlson. I agree that invoking a suggestion and having nothing happen feels like a bug, which is worse than inferring a useless any.

@sandersn sandersn requested review from DanielRosenwasser and a user October 29, 2018 17:34
@sandersn
Copy link
Member Author

Note that we should do this for unused locals and unused parameters errors as well, since they also can't be ts-ignored, but offer it nonetheless.

const type = inferTypeForVariableFromUsage(setAccessorDeclaration.name, program, cancellationToken) ||
inferTypeForVariableFromUsage(param.name, program, cancellationToken);
let type = inferTypeForVariableFromUsage(setAccessorDeclaration.name, program, cancellationToken);
if (type === program.getTypeChecker().getAnyType()) {
Copy link

Choose a reason for hiding this comment

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

Would it be better to use type.flags & TypeFlags.Any here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Short answer: no.
Long answer: here we are checking for exactly the fallback type produced inside inferFromUsage.ts, not other types that come from the checker like errorType. Those types are already filtered out in addCandidateType, which does use TypeFlags.Any.

@sandersn sandersn merged commit 60efb65 into master Oct 29, 2018
@sandersn sandersn deleted the dont-tsignore-implicitany-suggestions branch October 29, 2018 20:23
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.

1 participant