Libraries
    Preparing search index...

    Interface ArrayBuiltinExtensions<TElementSchema>

    Methods added to ArraySchemaBuilder by the built-in array extension pack.

    WORKAROUND: This interface duplicates the method signatures from arrayExtensions so that JSDoc survives into the published .d.ts files. TypeScript strips JSDoc when method signatures are reconstructed through the FixedMethods mapped type (conditional infer loses comments). Remove this interface once TypeScript preserves JSDoc through mapped types / conditional type inference.

    interface ArrayBuiltinExtensions<
        TElementSchema extends
            SchemaBuilder<any, any, any, any, any> = SchemaBuilder<any, any, any>,
    > {
        nonempty(
            errorMessage?: ValidationErrorMessageProvider<
                ArraySchemaBuilder<
                    any,
                    true,
                    false,
                    undefined,
                    false,
                    {},
                    any[]
                    | unknown[],
                >,
            >,
        ): ArrayExtReturn<TElementSchema>;
        unique(
            keyFn?: (item: any) => unknown,
            errorMessage?: ValidationErrorMessageProvider<
                ArraySchemaBuilder<
                    any,
                    true,
                    false,
                    undefined,
                    false,
                    {},
                    any[]
                    | unknown[],
                >,
            >,
        ): ArrayExtReturn<TElementSchema>;
    }

    Type Parameters

    Index

    Methods

    • Validates that the array contains at least one element.

      Parameters

      • OptionalerrorMessage: ValidationErrorMessageProvider<
            ArraySchemaBuilder<
                any,
                true,
                false,
                undefined,
                false,
                {},
                any[]
                | unknown[],
            >,
        >

        custom error message or function to generate one

      Returns ArrayExtReturn<TElementSchema>

      a new schema builder with the nonempty validator applied

      array().nonempty();
      array().nonempty('At least one item required');
    • Validates that all elements in the array are unique.

      For primitive elements, uses strict equality. For objects, pass a keyFn that extracts a comparison key from each element.

      Parameters

      • OptionalkeyFn: (item: any) => unknown

        optional function to extract a comparison key from each element

      • OptionalerrorMessage: ValidationErrorMessageProvider<
            ArraySchemaBuilder<
                any,
                true,
                false,
                undefined,
                false,
                {},
                any[]
                | unknown[],
            >,
        >

        custom error message or function to generate one

      Returns ArrayExtReturn<TElementSchema>

      a new schema builder with the unique validator applied

      array().unique();
      array().unique((item) => item.id);
      array().unique(undefined, 'No duplicates allowed');