type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; // Example Usage: type A = { a: string }; type B = { b: number }; type C = { c: boolean }; type ABC_Union = A | B | C; type ABC_Intersection = UnionToIntersection; // Expected: A & B & C const combined: ABC_Intersection = { a: "hello", b: 123, c: true, }; // Useful for scenarios like merging callback functions: type Callback1 = (x: string) => void; type Callback2 = (y: number) => void; type Callback3 = (z: boolean) => void; type MergedCallbacks = UnionToIntersection; // MergedCallbacks is equivalent to (x: string) => void & (y: number) => void & (z: boolean) => void // This effectively means a function that can accept any of the parameters, // though its primary use is for object property merging or specific advanced patterns. // A more practical application: creating an object with properties from each union member interface UserSettings { theme: 'dark' | 'light'; } interface UserPermissions { isAdmin: boolean; canEdit: boolean; } interface UserProfile { name: string; email: string; } type AllUserConfig = UnionToIntersection; /* Expected: { theme: 'dark' | 'light'; isAdmin: boolean; canEdit: boolean; name: string; email: string; } */ const userConfig: AllUserConfig = { theme: 'dark', isAdmin: true, canEdit: false, name: 'John Doe', email: 'john@example.com' };