Skip to content

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

Open
@seansfkelley

Description

@seansfkelley

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions