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

    Class VineUnionOfTypes<Schema>

    Vine union of types represents a union data type that automatically determines which schema to apply based on the value's type.

    Unlike regular unions that require explicit conditionals, unionOfTypes uses each schema's IS_OF_TYPE method to automatically detect the appropriate schema based on the input value's type.

    const schema = vine.unionOfTypes([
    vine.string(),
    vine.number(),
    vine.boolean()
    ])
    const schema = vine.unionOfTypes([
    vine.object({ type: vine.literal('user'), name: vine.string() }),
    vine.object({ type: vine.literal('admin'), permissions: vine.array(vine.string()) })
    ])

    Type Parameters

    • Schema extends SchemaTypes

      The schema types that make up this union

    Implements

    Index

    Constructors

    Properties

    "[ITYPE]": Schema[typeof ITYPE]

    The input type of the schema

    "[OTYPE]": Schema[typeof OTYPE]

    The output type of the schema

    "[COTYPE]": Schema[typeof COTYPE]

    The camelCase output type of the schema

    Methods

    • Compiles the union of types schema to a compiler node.

      Creates conditional branches for each schema using their IS_OF_TYPE methods to determine which schema matches the input value.

      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