After defining the EventType as either "TYPE A" or "TYPE B", I am looking to create a type for an array that can only contain one or both of these event types.
Simply typing it as an EventType[]
allows duplicates, which is not ideal.
type Test = EventType[]
const eventTypes:Test = ["TYPE A", "TYPE B", "TYPE B", "TYPE A"]
Listing out all available options individually becomes cumbersome when there are more than two options:
type Test = ["TYPE A"] | ["TYPE B"] | ["TYPE A", "TYPE B"];
// This will throw a compiler error
const eventTypes:Test = ["TYPE A", "TYPE B", "TYPE B", "TYPE A"]
Is there a way to achieve this constraint at the type level in TypeScript without explicitly enumerating every option?