@vinejs/vine - v4.2.0
    Preparing search index...

    Class VineTuple<Schema, Input, Output, CamelCaseOutput>

    VineTuple represents a fixed-length array where each position has a specific schema type. Unlike VineArray which uses the same schema for all elements, tuples allow different types at different positions, similar to TypeScript tuples.

    const schema = vine.tuple([
    vine.string(),
    vine.number(),
    vine.boolean()
    ])

    const result = await vine.validate({
    schema,
    data: ['hello', 42, true]
    })

    Type Parameters

    • Schema extends SchemaTypes[]

      Array of schema types for each tuple position

    • Input extends any[]

      Expected input type for the tuple

    • Output extends any[]

      Output type after validation and transformation

    • CamelCaseOutput extends any[]

      Output type with camelCase property names

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    "[ITYPE]": Input

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": Output

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": CamelCaseOutput

    Type marker for camelCase output type inference

    "[UNIQUE_NAME]": string = 'vine.array'

    Unique name identifier for union type resolution

    Methods

    • Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working with.

      Parameters

      • callback: ParseFn

        Parser function to transform the input value

      Returns this

      This schema instance for method chaining

      vine.string().parse((value) => {
      return typeof value === 'string' ? value.trim() : value
      })
    • Type checker function to determine if a value is an array. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns value is any[]

      True if the value is an array

    • Allows additional elements beyond the defined tuple length to pass through validation. By default, tuples enforce exact length matching. This method relaxes that constraint.

      Type Parameters

      • Value

      Returns VineTuple<
          Schema,
          [...Input[], ...Value[]],
          [...Output[], ...Value[]],
          [...CamelCaseOutput[], ...Value[]],
      >

      This tuple schema with unknown properties allowed

      const schema = vine.tuple([
      vine.string(),
      vine.number()
      ]).allowUnknownProperties()

      // Now ['hello', 42, 'extra'] will pass validation
    • Clones the VineTuple schema including all position schemas, validations, and options.

      Returns this

      A cloned instance of this VineTuple schema

    • Compiles the tuple schema to a compiler node for validation.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options

      Returns TupleNode

      Compiled tuple node for validation