NumberSchema
Validates numbers. NaN is rejected before any refinement runs.
local Level = v.number():integer():min(1):max(100)
Properties
minimum
This item is read only and cannot be modified. Read OnlyReflectionNumberSchema.minimum: number?
Smallest value this schema accepts, or nil if it is unbounded. Set by
NumberSchema:min.
maximum
This item is read only and cannot be modified. Read OnlyReflectionNumberSchema.maximum: number?
Largest value this schema accepts, or nil if it is unbounded. Set by
NumberSchema:max.
isOptional
This item is read only and cannot be modified. Read OnlyReflectionNumberSchema.isOptional: booleanAlways false.
access
This item is read only and cannot be modified. Read OnlyReflectionNumberSchema.access: "readwrite"
Always "readwrite". Chain NumberSchema:readonly or
NumberSchema:writeonly to change it.
Functions
_validate
ParsingNumberSchema:_validate(value: unknown) → Result<number>
Validates value without throwing. All refinements run, so the returned
issues describe every failure rather than only the first.
parse
ParsingNumberSchema:parse(value: unknown) → numberValidates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` fails validation |
min
RefinementRequires the number to be greater than or equal to n.
max
RefinementRequires the number to be less than or equal to n.
integer
RefinementRequires the number to have no fractional part. Infinities are rejected.
optional
WrapperWraps this schema so that nil is also accepted.
default
WrapperWraps this schema so that nil yields fallback instead of failing.
defaultWith
WrapperNumberSchema:defaultWith(produce: () → number--
Builds the value used when parsing nil
) → DefaultSchema<number>
Like NumberSchema:default, but calls produce on every parse instead of
reusing one value. Use it when the fallback is a table, since a single
table would otherwise be shared by every caller and mutable through any
of them.
The produced value is validated each time, so a producer that returns something invalid fails at parse rather than silently passing through.
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.