One approach could involve creating an interface for Events with different types such as a, b, or c.
You can define an interface that specifies each element property can have one instance of each type.
interface EventFilter {
elements: [EventA?, EventB?, EventC?];
}
A drawback of this method is that elements must be added in the exact order specified in the EventFilter interface.
interface Event {
type: 'a' | 'b' | 'c';
value: string;
}
interface EventA extends Event {
type: 'a';
}
interface EventB extends Event {
type: 'b';
}
interface EventC extends Event {
type: 'c';
}
interface EventFilter {
elements: [EventA?, EventB?, EventC?];
}
const app: EventFilter = {
elements: [
{ type: 'a', value: '1' },
{ type: 'b', value: '1' }
],
}
Unfortunately, to achieve a flexible array allowing elements to be in any order, you would need to list all permissible combinations explicitly.
interface EventFilter {
elements: [EventA?, EventB?, EventC?] | [EventA?, EventC?, EventB?]
| [EventB?, EventA?, EventC?] | [EventB?, EventC?, EventA?]
| [EventC?, EventA?, EventB?] | [EventC?, EventB?, EventA?];
}
const app: EventFilter = {
elements: [
{ type: 'c', value: '1' },
{ type: 'a', value: '1' },
],
}