Let’s say I have an interface such as:
interface DataShapes {
shape1: { a: number };
shape2: { b: string };
}
Is it possible to define a type ToUnion
such that ToUnion<DataShapes>
produces a discriminated union like:
| { key: 'shape1', value: { a: number } }
| { key: 'shape2', value: { b: string } }