microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.6k stars 12.44k forks source link

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

Open seansfkelley opened 3 years ago

seansfkelley commented 3 years ago

Suggestion

🔍 Search Terms

✅ Viability Checklist

My suggestion meets these guidelines:

⭐ Suggestion

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

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 commented 3 years ago

This sounds related: #45295

seansfkelley commented 3 years ago

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>. 🤔