I have a union of two different types, and an array of this union type.
I want to get an error when I try to pass a combination that doesn't exist on any of the interfaces.
interface IMenuItem {
title: string;
theme: 'primary' | 'secondary';
}
interface IMenuDivider {
isDivider: boolean;
margin?: number;
}
type TItem = IMenuItem | IMenuDivider;
const items: TItem[] = [
{
title: 'item title',
isDivider: true // doesn't error
}
]
I'd expect this example to trigger an error since this combination isn't defined in any of the interfaces composing the union.
How should I type my TItem to achieve this?
Thanks!