I'm tying to write a helper type that intersects all types in a tuple type but with one logic in mind:
The types that add the most restrictions "win" over the others. The final intersection must be the most-restricted type that can be assigned to every individual type of the tuple.
An example. Let's call that helper type Join
. Here are some assertions :
Join<[string, any[]]> // string & any[]
Join<[string, number, boolean]> // never (string & number & boolean)
Join<[string, { z: boolean }]> // string & { z: boolean }
Join<[{ x: number }, { y: string }]> // { x: number } & { y: string }
Join<[{ x: number }, { y: string }, { z: boolean }]> // { x: number } & { y: string } & { z: boolean }
Join<[any, { y: string }]> // { y: string }
Join<[any, string]> // string
Join<[unknown, string]> // string
Join<[any, unknown, any, any]> // unknown
Join<[any, any, any]> // any
I have no idea where to start. Any idea ? Thank you.