microsoft / microsoft/TypeScript
Evaluate user-defined generic type aliases on hover
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Let's say we have a class like this:
class A
{
readonly x = 99;
s: string;
constructor(initialiser: { [K in Exclude<keyof A, 'x'>]: A[K] })
{
for (const k in initialiser) this[k] = initialiser[k];
}
}
Now, when I hover over the ctor param, VS Code shows me the type: { s: string; }.
Since I need such an initialiser for several classes, I have written a generic type alias:
type InitialiserExclude<C, Keys extends keyof C> = { [K in Exclude<keyof C, Keys>]: C[K] };
When I replace the initialiser type by InitialiserExclude<A, 'x'>, that's exactly what I see when hovering over the ctor param.
It would be very nice if VS Code evaluated such user-defined type aliases as it does with e. g. the built-in Exclude<T, U> and showed the resulting object type.
This is not only a matter of usability of the class. To create more complex initialiser types, it can be necessary to define multiple generic type aliases and use one within another, and the only way I know to check if such an initialiser works as expected is to declare a variable with that type and hover over it.
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
Use the TypeScript examples in the issue as the reproduction: compare hover output for the inline mapped type, built-in Exclude, and the user-defined InitialiserExclude alias. Start by tracing the language-service hover behavior for these types. Done means hovering over the constructor parameter expands the user-defined alias to the resulting object type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100