type Fruit = Partial<{
color: string;
size: string;
}>;
interface Apple extends Fruit {
name: "apple";
}
interface Banana extends Fruit {
name: "banana";
}
type Food = Apple | Banana;
const fruits: Food[] = [
{
name: "apple",
color: "red",
},
{
name: "banana",
size: "big",
}
];
const limes: Food[] = [
{
name: "lime", // error: Type '"lime"' is not assignable to type '"apple" | "banana"'
}
];