Let's say these are the basic types I'm working with:
type MyUnion = 'a' | 'b' | 'c'
type MyType = {myKey: MyUnion}
Hovering over MyType
doesn't expand MyUnion
:
So I created a helper type that recursively expands deeply nested types:
type Expand<T> = {
[K in keyof T]: T[K]
} & {}
Let me show you Expand
in action. Here's some types I'll play around with:
type SomeObj = {
a: number,
b: string
}
type TopLevel = {c: SomeObj}
type TopLevelExpanded = Expand<TopLevel>
Hovering over TopLevel
shows the "before":
And hovering over TopLevelExpanded
shows the "after", with the nested types expanded:
Putting it all together, I had hoped that using this Expand
type helper would also expand unions, but it doesn't:
Is there a way in TypeScript to expand union types in Intellisense when hovering? I can't figure out what's wrong with my Expand
helper type.