Let's say I have an interface
export interface IAlert {
cta?: CTA;
description?: string;
title?: string;
}
How would you type this so that at least one property is passed in, but also allow for all three to be passed in.
I have tried...
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 happy with the error message it presents...
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'm unsure of how to either maintain the use of an interface and require a minimum of one property to be passed in or to use a type
, but provide a more meaningful error.