ArraySchema
Validates a contiguous array where every element matches one inner schema. Tables carrying non-array keys are rejected outright.
The array you pass in is returned untouched unless an element fills a value in, which only a nested DefaultSchema does. In that case the input is shallow copied and the filled values written to the copy, so parsing never modifies what it was given and never allocates a copy it does not need.
local Scores = v.array(v.number():integer()):max(4)
Properties
minimum
This item is read only and cannot be modified. Read OnlyReflectionArraySchema.minimum: number?
Fewest elements this schema accepts, or nil if it is unbounded. Set
by ArraySchema:min.
maximum
This item is read only and cannot be modified. Read OnlyReflectionArraySchema.maximum: number?
Most elements this schema accepts, or nil if it is unbounded. Set by
ArraySchema:max.
isOptional
This item is read only and cannot be modified. Read OnlyReflectionArraySchema.isOptional: booleanAlways false.
access
This item is read only and cannot be modified. Read OnlyReflectionArraySchema.access: "readwrite"Always "readwrite". Chain :readonly() or :writeonly() to change it.
Functions
safeParse
ParsingArraySchema:safeParse(value: unknown) → Result<{T}>Validates every element, reporting each failure with its index in the issue path.
parse
ParsingArraySchema:parse(value: unknown) → {T}Validates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` fails validation |
min
RefinementRequires the array to hold at least n elements.
max
RefinementRequires the array to hold at most n elements.
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 array would be shared by
every parse.
defaultWith
WrapperArraySchema: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
Wrapper
Wraps this schema so that a field using it is typed read. The array
itself stays mutable; it is the field that cannot be reassigned.
writeonly
WrapperWraps this schema so that a field using it is typed write.