microsoft / microsoft/TypeScript
Default type parameter values always shown on hover
Nobody has claimed this yet.
- 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
💻 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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