I would like to combine multiple interfaces that have properties with conflicting types, where the combined interface is a list of all potential keys with the widest possible type definition for each key.
Example:
interface Dog {
type: "dog";
name: string;
owner: "Bob" | "Bobette";
}
interface Cat {
type: "cat";
name: number;
owner: "Bob" | "Bobette" | "Jeff";
}
interface Giraffe {
type: "giraffe";
height: number;
}
type CombinedInterface<Dog, Cat, Giraffe> would equal {
type: "dog" | "cat" | "giraffe";
name?: string | number;
owner?: "Bob" | "Bobette" | "Jeff";
height?: number;
}
Where CombinedInterface could take any number of interfaces.
Thanks in advance for any help!
Edit for clarity:
CombinedInterface would be a generic, e.g. type CombinedInterface<I1, I2, ..., IN>
, for which CombinedInterface<Dog, Cat, Giraffe>
would return the type shown above.