Skip to content

Setting to hide inlay hints for implicitly-typed variables that are set to literals #46122

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

Open
5 tasks done
seansfkelley opened this issue Sep 28, 2021 · 2 comments
Open
5 tasks done
Labels
Domain: Inlay Hints In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@seansfkelley
Copy link

seansfkelley commented Sep 28, 2021

Suggestion

πŸ” Search Terms

  • inlay hints
  • implicit variable

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Change the typescript.inlayHints.variableTypes.enabled setting from a boolean to a enumeration, with options:

  • none
  • non-literals
  • all

It may make sense to apply this same treatment to typescript.inlayHints.propertyDeclarationTypes.enabled as well.

πŸ“ƒ Motivating Example

Here is a screenshot of the snippet in my codebase that was the direct inspiration for this request:

image

The inlay hints are, to me, pretty noisy here.

  1. It's obvious what the inferred type of the string literal and object literal will be. The function literal as well, though if I were to remove the type annotations I would be relying on other inlay hints to help me there.
  2. The hints for the object literal and function literal are almost useless, even if I wanted to be told the type. It does not take a particularly large object or complex function definition to hit the ellipsis limit for unnamed/unaliased object/function types.

However, I don't want to disable it for all implicitly-typed variables. This inlay hint from later in the same file is very non-obvious because it's behind a wordy function call:

image

πŸ’» Use Cases

n/a? I think the motivating example section covers this.

@MartinJohns
Copy link
Contributor

This sounds related: #45295

@andrewbranch andrewbranch added Domain: Inlay Hints In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Sep 30, 2021
@seansfkelley
Copy link
Author

seansfkelley commented Oct 2, 2021

This might be tangential, but as a user it feels related, so I'll add it here anyway:

image

Maybe lump constructors in with "literals" so they don't appear when non-literals is set?

But of course, this is only redundant and not useful because the type parameters are explicitly specified. If they weren't, I'd probably like to know that the inferred type would be, e.g., Set<unknown>. πŸ€”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Inlay Hints In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants