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

    Class VineUnion<Conditional>

    Vine union represents a union data type. A union is a collection of conditionals and each condition has an associated schema.

    Unions allow you to define validation logic where different schemas are applied based on runtime conditions. Each conditional is evaluated in order, and the first matching condition's schema is used for validation.

    const schema = vine.object({
    userType: vine.string(),
    data: vine.union([
    vine.union.if(
    (value) => value.userType === 'admin',
    vine.object({ permissions: vine.array(vine.string()) })
    ),
    vine.union.else(
    vine.object({ role: vine.string() })
    )
    ])
    })

    Type Parameters

    Implements

    Index

    Constructors

    Properties

    "[ITYPE]": Conditional[typeof ITYPE]

    The input type of the schema

    "[OTYPE]": Conditional[typeof OTYPE]

    The output type of the schema

    "[COTYPE]": Conditional[typeof COTYPE]

    The camelCase output type of the schema

    Methods

    • Compiles the union schema to a compiler node.

      Parameters

      • propertyName: string

        The name of the property being validated

      • refs: RefsStore

        Reference store for tracking validators and conditionals

      • options: ParserOptions

        Parser options including camelCase transformation

      Returns UnionNode