Skip to main content

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 OnlyReflection
NumberSchema.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 OnlyReflection
NumberSchema.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 OnlyReflection
NumberSchema.isOptional: boolean

Always false.

access​

This item is read only and cannot be modified. Read OnlyReflection
NumberSchema.access: "readwrite"

Always "readwrite". Chain NumberSchema:readonly or NumberSchema:writeonly to change it.

Functions​

_validate​

Parsing
NumberSchema:_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​

Parsing
NumberSchema:parse(value: unknown) → number

Validates value and returns it, throwing on failure.

Errors

TypeDescription
"expected ..."Thrown when `value` fails validation

min​

Refinement
NumberSchema:min(
n: number--

Minimum value, inclusive

) → NumberSchema

Requires the number to be greater than or equal to n.

max​

Refinement
NumberSchema:max(
n: number--

Maximum value, inclusive

) → NumberSchema

Requires the number to be less than or equal to n.

integer​

Refinement
NumberSchema:integer() → NumberSchema

Requires the number to have no fractional part. Infinities are rejected.

optional​

Wrapper
NumberSchema:optional() → OptionalSchema<number>

Wraps this schema so that nil is also accepted.

default​

Wrapper
NumberSchema:default(
fallback: number--

Value used when parsing nil

) → DefaultSchema<number>

Wraps this schema so that nil yields fallback instead of failing.

defaultWith​

Wrapper
NumberSchema: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​

Wrapper
NumberSchema:readonly() → ReadonlySchema<number>

Wraps this schema so that a field using it is typed read.

writeonly​

Wrapper
NumberSchema:writeonly() → WriteonlySchema<number>

Wraps this schema so that a field using it is typed write.

Show raw api
{
    "functions": [
        {
            "name": "_validate",
            "desc": "Validates `value` without throwing. All refinements run, so the returned\nissues describe every failure rather than only the first.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "source": {
                "line": 1416,
                "path": "src/init.luau"
            }
        },
        {
            "name": "parse",
            "desc": "Validates `value` and returns it, throwing on failure.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "errors": [
                {
                    "lua_type": "\"expected ...\"",
                    "desc": "Thrown when `value` fails validation"
                }
            ],
            "source": {
                "line": 1446,
                "path": "src/init.luau"
            }
        },
        {
            "name": "min",
            "desc": "Requires the number to be greater than or equal to `n`.",
            "params": [
                {
                    "name": "n",
                    "desc": "Minimum value, inclusive",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NumberSchema"
                }
            ],
            "function_type": "method",
            "tags": [
                "Refinement"
            ],
            "source": {
                "line": 1464,
                "path": "src/init.luau"
            }
        },
        {
            "name": "max",
            "desc": "Requires the number to be less than or equal to `n`.",
            "params": [
                {
                    "name": "n",
                    "desc": "Maximum value, inclusive",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NumberSchema"
                }
            ],
            "function_type": "method",
            "tags": [
                "Refinement"
            ],
            "source": {
                "line": 1482,
                "path": "src/init.luau"
            }
        },
        {
            "name": "integer",
            "desc": "Requires the number to have no fractional part. Infinities are rejected.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NumberSchema"
                }
            ],
            "function_type": "method",
            "tags": [
                "Refinement"
            ],
            "source": {
                "line": 1499,
                "path": "src/init.luau"
            }
        },
        {
            "name": "optional",
            "desc": "Wraps this schema so that `nil` is also accepted.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "OptionalSchema<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1516,
                "path": "src/init.luau"
            }
        },
        {
            "name": "default",
            "desc": "Wraps this schema so that `nil` yields `fallback` instead of failing.",
            "params": [
                {
                    "name": "fallback",
                    "desc": "Value used when parsing `nil`",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1531,
                "path": "src/init.luau"
            }
        },
        {
            "name": "defaultWith",
            "desc": "Like [NumberSchema:default], but calls `produce` on every parse instead of\nreusing one value. Use it when the fallback is a table, since a single\ntable would otherwise be shared by every caller and mutable through any\nof them.\n\nThe produced value is validated each time, so a producer that returns\nsomething invalid fails at parse rather than silently passing through.",
            "params": [
                {
                    "name": "produce",
                    "desc": "Builds the value used when parsing `nil`",
                    "lua_type": "() -> number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1554,
                "path": "src/init.luau"
            }
        },
        {
            "name": "readonly",
            "desc": "Wraps this schema so that a field using it is typed `read`.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ReadonlySchema<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1568,
                "path": "src/init.luau"
            }
        },
        {
            "name": "writeonly",
            "desc": "Wraps this schema so that a field using it is typed `write`.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "WriteonlySchema<number>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1582,
                "path": "src/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "minimum",
            "desc": "Smallest value this schema accepts, or `nil` if it is unbounded. Set by\n[NumberSchema:min].",
            "lua_type": "number?",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1368,
                "path": "src/init.luau"
            }
        },
        {
            "name": "maximum",
            "desc": "Largest value this schema accepts, or `nil` if it is unbounded. Set by\n[NumberSchema:max].",
            "lua_type": "number?",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1378,
                "path": "src/init.luau"
            }
        },
        {
            "name": "isOptional",
            "desc": "Always `false`.",
            "lua_type": "boolean",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1387,
                "path": "src/init.luau"
            }
        },
        {
            "name": "access",
            "desc": "Always `\"readwrite\"`. Chain [NumberSchema:readonly] or\n[NumberSchema:writeonly] to change it.",
            "lua_type": "\"readwrite\"",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1397,
                "path": "src/init.luau"
            }
        }
    ],
    "types": [],
    "name": "NumberSchema",
    "desc": "Validates numbers. NaN is rejected before any refinement runs.\n\n```lua\nlocal Level = v.number():integer():min(1):max(100)\n```",
    "source": {
        "line": 1330,
        "path": "src/init.luau"
    }
}