TupleSchema
Validates a fixed sequence where each position has its own schema. Use it for packed argument lists and other positional payloads, where ArraySchema would only let you say that every element is the same shape.
Like ArraySchema, the input is returned untouched unless a position fills a value in, in which case it is shallow copied first.
local Waypoint = v.tuple({ v.string(), v.number():integer() })
Waypoint:parse({ "spawn", 3 }) --> { "spawn", 3 }
Waypoint:parse({ "spawn" }) --> errors: [2]: expected number, got nil
Waypoint:parse({ "a", 1, 2 }) --> errors: expected a tuple of 2 values, got 3
A position whose schema is optional or has a default may be left off the
end, since Lua cannot tell a trailing nil from a shorter list:
local Ping = v.tuple({ v.string(), v.number():default(0) })
Ping:parse({ "hello" }) --> { "hello", 0 }
Properties
minimum
This item is read only and cannot be modified. Read OnlyReflectionTupleSchema.minimum: number?
Always nil. How few values a tuple accepts depends on how many of its
trailing positions tolerate nil, so there is no single number.
maximum
This item is read only and cannot be modified. Read OnlyReflectionTupleSchema.maximum: number?The number of positions, which is the most values this schema accepts.
isOptional
This item is read only and cannot be modified. Read OnlyReflectionTupleSchema.isOptional: booleanAlways false.
access
This item is read only and cannot be modified. Read OnlyReflectionTupleSchema.access: "readwrite"Always "readwrite". Chain :readonly() or :writeonly() to change it.
Functions
safeParse
ParsingTupleSchema:safeParse(value: unknown) → Result<{T}>Validates each position against its own schema, reporting failures with the index in the issue path.
parse
ParsingTupleSchema:parse(value: unknown) → {T}Validates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` fails validation |
optional
WrapperWraps this schema so that nil is also accepted.
default
Wrapper
Wraps this schema so that nil yields fallback instead of failing.
Prefer passing a function, since a constant table would be shared by
every parse.
defaultWith
WrapperTupleSchema:defaultWith(produce: () → {T}--
Builds the value used when parsing nil
) → DefaultSchema<{T}>
Like :default, but calls produce on every parse instead of reusing
one value. Prefer it here, since a single table would otherwise be
shared by every caller and mutable through any of them.
The produced value is validated each time.
readonly
WrapperWraps this schema so that a field using it is typed read.
writeonly
WrapperWraps this schema so that a field using it is typed write.