LiteralSchema
Accepts exactly one value, compared with ==. Use it where a field may only
hold a specific constant, and combine several through ObjectSchema fields
to describe a tagged shape.
local Consented = v.literal(true)
local Kind = v.literal("player")
Consented:parse(true) --> true
Consented:parse(false) --> errors: expected true, got false
Kind:parse("npc") --> errors: expected "player", got "npc"
Properties
value
This item is read only and cannot be modified. Read OnlyReflectionLiteralSchema.value: TThe one value this schema accepts.
isOptional
This item is read only and cannot be modified. Read OnlyReflectionLiteralSchema.isOptional: booleanAlways false.
access
This item is read only and cannot be modified. Read OnlyReflectionLiteralSchema.access: "readwrite"Always "readwrite". Chain :readonly() or :writeonly() to change it.
Functions
safeParse
ParsingLiteralSchema:safeParse(value: unknown) → Result<T>Validates value without throwing.
parse
ParsingLiteralSchema:parse(value: unknown) → TValidates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` is anything else |
optional
WrapperWraps this schema so that nil is also accepted.
default
WrapperWraps this schema so that nil yields fallback instead of failing.
defaultWith
WrapperLiteralSchema:defaultWith(produce: () → T--
Builds the value used when parsing nil
) → DefaultSchema<T>Like :default, but calls produce on every parse.
readonly
Wrapper
Wraps this schema so that a field using it is typed read. Pairing it
with a singleton annotation gives an object a tag that cannot be
overwritten after parsing.
writeonly
WrapperWraps this schema so that a field using it is typed write.