Skip to content

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 a user and DanielRosenwasser 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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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