Forgive me if this question has already been posed. I made an effort to search for a solution, but it seems I may not be using the correct terms.
The issue arises with this particular structure. It involves a simple mapped type:
type Mapped = {
square: {
size: number;
};
rectangle: {
width: number;
height: number;
};
};
Next, I have a type that is attempting to create a union:
type Unionize<T> = {
name: keyof T;
data: T[keyof T];
};
type Out = Unionize<Mapped>;
This results in the following type:
type Generated = {
name: "square" | "rectangle";
data: {
size: number;
} | {
width: number;
height: number;
};
}
However, what I truly desire is this, as it would allow me to utilize discriminated unions to deduce and verify data properties.
type Wanted = {
name: "square";
data: {
size: number;
};
} | {
name: "rectangle";
data: {
width: number;
height: number;
};
}