Function matchExactSchema

  • Given a Schema, returns a Type Guard that checks that the given value is a object exactly implementing the entries of the Schema.

    This Type Guard returns false if a given value contains keys that are not specified in the Schema. If you want to allow unknown keys, see matchSchema

    Example

    import { matchExactSchema,  match } from 'type-guard-helpers'

    const test = {} as unknown
    const isFoo = match'foo');
    const isBar = match'bar');
    const isFooObject = matchExactSchema({
    foo: isFoo,
    bar: isBar
    })

    if(isFooObject(test)){
    test; // { readonly foo: "foo"; readonly bar: "bar"; }
    }

    Type Parameters

    Parameters

    • schema: Schema

    Returns MatchExactSchemaFn<Schema>

Generated using TypeDoc