I believe there isn't a direct way to instruct your IDE to perform this task automatically, but you have the option to create a type function that will determine the type you require. Referencing the response from a similar question, I would define a function called Expand
:
type Expand<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
This function walks through all properties of a type (or union of types), including those from various intersections, and consolidates them into a single object type. You can then either utilize Expand<C>
directly or assign C
as Expand<A & B>
:
type ExpandedC = Expand<A & B>;
/*
type ExpandedC = {
a: number;
b: string;
c: boolean;
d: Date;
}
*/
Ultimately achieving the desired result. Hopefully, this information proves beneficial to you. Best of luck!
Playground link for code illustration