microsoft / microsoft/TypeScript

Default type parameter values always shown on hover

Open
#59,385 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

default parameters hover

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://tsplay.dev/mpkKgN

💻 Code
export abstract class Kind<
    hkt extends (...args: any[]) => unknown = (...args: any[]) => unknown
> {
    declare readonly args: unknown
    abstract readonly hkt: hkt
}

// Hover: Kind<(...args: any[]) => unknown>
type SomeHkt = Kind
🙁 Actual behavior

Kind's defaulted parameter is displayed on hover.

🙂 Expected behavior

Defaultable generic parameters should not be printed if they are unset in the instantiation and/or explicitly set to their default value.

This could also apply to .d.ts, although that's viewed less often.

Additional information about the issue

This is obviously not a bug but a request that would help reduce visual clutter for many types. Types with several parameters with non trivial default values are relatively common, especially when those defaults are expanded recursively.

It also occurred to me that when combined with autofixes, this could also make types written to a user file much more usable. When using --isolatedDeclarations, one of the biggest problems with the autofixes is that they'd often pull in types with several generic parameters with long defaults, and end up writing some massive type instead of just a single identifier.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start with the linked TypeScript Playground and inspect the hover for SomeHkt, then trace the compiler path that formats generic type parameters. Done means defaulted parameters are omitted when unset or explicitly equal to their defaults, including the stated .d.ts and isolatedDeclarations cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.