In Typescript, when inspecting types defined by intersection, I see a hint identical to original definition:
but I would like to see the resulting shape, something like this:
what is a quick / efficient way to do this?
In Typescript, when inspecting types defined by intersection, I see a hint identical to original definition:
but I would like to see the resulting shape, something like this:
what is a quick / efficient way to do this?
I don't think there's any way to ask your IDE to do this automatically, but you can make a type function that calculates the type you're looking for. From the answer to the question is duplicates, I would write Expand
:
type Expand<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
which takes a type (or union of types) and walks through all of its properties, even if they come from multiple intersections, and packages it (or each union member) into a single object type. Then you could either write Expand<C>
or you could define C
to be Expand<A & B>
:
type ExpandedC = Expand<A & B>;
/*
type ExpandedC = {
a: number;
b: string;
c: boolean;
d: Date;
}
*/
which is what you wanted. Okay, hope that helps; good luck!