Skip to main content

CompositionTypeSatisfiesEnum (Type)

Type Aliases

CompositionTypeSatisfiesEnum<T, _Enum>

type CompositionTypeSatisfiesEnum<T, _Enum>: unknown;

Helper type to validate that a union of interfaces with a field of type that is based on an enum is complete.

For example:

enum ObjectiveType {
Foo,
Bar,
Baz,
}

interface FooObjective {
type: ObjectiveType.Foo;
fooThing: number;
}

interface BarObjective {
type: ObjectiveType.Bar;
barThing: string;
}

type Objective = FooObjective | BarObjective;
type _Test = CompositionTypeSatisfiesEnum<Objective, ObjectiveType>;

In this example, Test would be flagged by TypeScript because Objective does not contain an entry for BazObjective.

Type Parameters

Type Parameter
T extends object
_Enum extends T["type"]

Defined in

types/CompositionTypeSatisfiesEnum.ts:31