Function matchPartialSchema

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

    The difference between this Type Guard and matchExactSchema is that this Type Guard will allow additional entries that are not specified in the Schema.

    The difference between this Type Guard and matchSchema is that this Type Guard will allow additional entries that are not specified in the Schema.

    Example

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

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

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

    Type Parameters

    Parameters

    • schema: Schema

    Returns MatchPartialSchemaFn<Schema>

Generated using TypeDoc