Skip to content

CompositionTypeSatisfiesEnum (Type)

type CompositionTypeSatisfiesEnum<T, _Enum> = unknown;

Defined in: types/CompositionTypeSatisfiesEnum.ts:31

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 Parameter
T extends object
_Enum extends T["type"]