Function properties

  • a schema that accepts named and optional properties as well as properties not listed

    This function has many overloads to account for the different ways to specify optional and non-optional properties, However, effectively either props or oprops must be specified, and additional is a boolean value.

    Type Parameters

    • const P extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>
    • const O extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: P
    • oprops: O
    • additional: true

    Returns CompiledSchema<{
        -readonly [K in keyof (Required<P> & Partial<O> & Record<string, unknown>)]: (P & O)[K] extends CompiledSchema<infer T, unknown>
            ? T
            : unknown
    }, {
        additionalProperties: true;
        optionalProperties: {
            -readonly [K in keyof O]: O[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
        properties: {
            -readonly [K in keyof P]: P[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties({ bool: boolean() }, { opt: boolean() }, true);
    
  • a schema that accepts named properties as well as properties not listed

    Type Parameters

    • const P extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: P
    • oprops: undefined
    • additional: true

    Returns CompiledSchema<{
        -readonly [K in keyof (Required<P> & Record<string, unknown>)]: P[K] extends CompiledSchema<infer T, unknown>
            ? T
            : unknown
    }, {
        additionalProperties: true;
        properties: {
            -readonly [K in keyof P]: P[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties({ bool: boolean() }, undefined, true);
    
  • a schema that accepts optional properties as well as properties not listed

    Type Parameters

    • const O extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: undefined
    • oprops: O
    • additional: true

    Returns CompiledSchema<{
        -readonly [K in keyof (Partial<O> & Record<string, unknown>)]: O[K] extends CompiledSchema<infer T, unknown>
            ? T
            : unknown
    }, {
        additionalProperties: true;
        optionalProperties: {
            -readonly [K in keyof O]: O[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties(undefined, { opt: boolean() });
    
  • a schema that accepts named and optional properties

    Type Parameters

    • const P extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>
    • const O extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: P
    • oprops: O
    • Optional additional: false

    Returns CompiledSchema<{
        -readonly [K in keyof (Required<P> & Partial<O>)]: (P & O)[K] extends CompiledSchema<infer T, unknown>
            ? T
            : never
    }, {
        optionalProperties: {
            -readonly [K in keyof O]: O[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
        properties: {
            -readonly [K in keyof P]: P[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties({ bool: boolean() }, { opt: boolean() });
    
  • a schema that accepts named properties

    Type Parameters

    • const P extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: P
    • Optional oprops: undefined
    • Optional additional: false

    Returns CompiledSchema<{
        -readonly [K in keyof Required<P>]: P[K] extends CompiledSchema<infer T, unknown>
            ? T
            : never
    }, {
        properties: {
            -readonly [K in keyof P]: P[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties({ bool: boolean() });
    
  • a schema that accepts optional properties

    Type Parameters

    • const O extends Readonly<Record<string, CompiledSchema<unknown, unknown>>>

    Parameters

    • props: undefined
    • oprops: O
    • Optional additional: false

    Returns CompiledSchema<{
        -readonly [K in keyof Partial<O>]: O[K] extends CompiledSchema<infer T, unknown>
            ? T
            : never
    }, {
        optionalProperties: {
            -readonly [K in keyof O]: O[K] extends CompiledSchema<unknown, infer S>
                ? S
                : never
        };
    }>

    Example

    const schema = properties(undefined, { opt: boolean() });