Skip to main content

BooleanSchema

Validates booleans. Truthy values that are not booleans, such as 1 or "true", are rejected.

local Enabled = v.boolean()

Properties​

isOptional​

This item is read only and cannot be modified. Read OnlyReflection
BooleanSchema.isOptional: boolean

Always false. Booleans carry no minimum or maximum, since neither means anything for two values.

access​

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

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

Functions​

_validate​

Parsing
BooleanSchema:_validate(value: unknown) → Result<boolean>

Validates value without throwing.

parse​

Parsing
BooleanSchema:parse(value: unknown) → boolean

Validates value and returns it, throwing on failure.

Errors

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

optional​

Wrapper
BooleanSchema:optional() → OptionalSchema<boolean>

Wraps this schema so that nil is also accepted.

default​

Wrapper
BooleanSchema:default(
fallback: boolean--

Value used when parsing nil

) → DefaultSchema<boolean>

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

defaultWith​

Wrapper
BooleanSchema:defaultWith(
produce: () → boolean--

Builds the value used when parsing nil

) → DefaultSchema<boolean>

Like BooleanSchema: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
BooleanSchema:readonly() → ReadonlySchema<boolean>

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

writeonly​

Wrapper
BooleanSchema:writeonly() → WriteonlySchema<boolean>

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

Show raw api
{
    "functions": [
        {
            "name": "_validate",
            "desc": "Validates `value` without throwing.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "source": {
                "line": 1658,
                "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": "boolean"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "errors": [
                {
                    "lua_type": "\"expected ...\"",
                    "desc": "Thrown when `value` fails validation"
                }
            ],
            "source": {
                "line": 1684,
                "path": "src/init.luau"
            }
        },
        {
            "name": "optional",
            "desc": "Wraps this schema so that `nil` is also accepted.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "OptionalSchema<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1701,
                "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": "boolean"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1716,
                "path": "src/init.luau"
            }
        },
        {
            "name": "defaultWith",
            "desc": "Like [BooleanSchema: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": "() -> boolean"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1739,
                "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<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1753,
                "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<boolean>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1767,
                "path": "src/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "isOptional",
            "desc": "Always `false`. Booleans carry no `minimum` or `maximum`, since neither\nmeans anything for two values.",
            "lua_type": "boolean",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1632,
                "path": "src/init.luau"
            }
        },
        {
            "name": "access",
            "desc": "Always `\"readwrite\"`. Chain [BooleanSchema:readonly] or\n[BooleanSchema:writeonly] to change it.",
            "lua_type": "\"readwrite\"",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1642,
                "path": "src/init.luau"
            }
        }
    ],
    "types": [],
    "name": "BooleanSchema",
    "desc": "Validates booleans. Truthy values that are not booleans, such as `1` or\n`\"true\"`, are rejected.\n\n```lua\nlocal Enabled = v.boolean()\n```",
    "source": {
        "line": 1599,
        "path": "src/init.luau"
    }
}