Type-level equivalent of the satisfies operator in TypeScript.
satisfies
Ensures that T conforms to Base. If T includes keys not present in Base, a compile-time error is produced by returning CustomTypeError, listing the unknown fields.
T
Base
CustomTypeError
The type to validate
The expected shape
type Result = Satisfies< //@ts-expect-error { a: string } does not satisfy { a: string; b: number } { a: string }, { a: string; b: number }>; Copy
type Result = Satisfies< //@ts-expect-error { a: string } does not satisfy { a: string; b: number } { a: string }, { a: string; b: number }>;
type Result = Satisfies<{ a: string; c: boolean }, { a: string }>;// ^?// {// [error]: {// message: "type may only specify known fields";// unknownFields: "c";// }// } Copy
type Result = Satisfies<{ a: string; c: boolean }, { a: string }>;// ^?// {// [error]: {// message: "type may only specify known fields";// unknownFields: "c";// }// }
Type-level equivalent of the
satisfiesoperator in TypeScript.Ensures that
Tconforms toBase. IfTincludes keys not present inBase, a compile-time error is produced by returningCustomTypeError, listing the unknown fields.