utilitypes-ts
    Preparing search index...

    Type Alias Satisfies<T, Base>

    Satisfies: Exclude<UnionKey<T>, UnionKey<Base>> extends never
        ? T
        : CustomTypeError<
            {
                message: "type may only specify known fields";
                unknownFields: Exclude<UnionKey<T>, UnionKey<Base>>;
            },
        >

    Type-level equivalent of the satisfies operator in TypeScript.

    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.

    Type Parameters

    • T extends Base

      The type to validate

    • Base

      The expected shape

    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";
    // }
    // }