Imagine having an interface like this:
export interface IAlert {
cta?: CTA;
description?: string;
title?: string;
}
How can you set up the typing so that at least one property is required to be passed in, but still allow for all three to be included?
I attempted the following...
export type TAlert = {
type?: EAlertType;
} & (
| {
cta: CTA;
description?: string;
title?: string;
}
| {
cta?: CTA;
description: string;
title?: string;
}
| {
cta?: CTA;
description?: string;
title: string;
}
);
However, I'm not satisfied with the error message it generates...
Type '{}' is not assignable to type 'IntrinsicAttributes & TAlert'.
Property 'title' is missing in type '{}' but required in type '{ cta?: any; description?: string; title: string; }'
I am unsure whether to stick with using an interface and mandating a minimum of one property, or switch to a type
while improving the error message.