Skip to main content

DatatypeSchema

Validates a Roblox datatype by its typeof name, so a table that merely carries the same fields is rejected — useful when the value arrived over a remote, where anything can be sent.

Reached through the named constructors rather than built directly: Vet.color3 and Vet.udim2 both return one of these.

local Tint = v.color3()
local Size = v.udim2()

Tint:parse(Color3.new(1, 0, 0))      --> Color3(1, 0, 0)
Tint:parse({ R = 1, G = 0, B = 0 })  --> errors: expected Color3, got table
Size:parse(UDim2.fromScale(1, 1))    --> UDim2

Each datatype schema holds no state beyond the name it checks, so the constructors hand out one frozen shared instance rather than allocating.

Properties​

typeName​

This item is read only and cannot be modified. Read OnlyReflection
DatatypeSchema.typeName: string

The typeof name this schema accepts, such as "Color3".

isOptional​

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

Always false. Datatypes carry no minimum or maximum.

access​

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

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

Functions​

safeParse​

Parsing
DatatypeSchema:safeParse(value: unknown) → Result<T>

Validates value without throwing.

parse​

Parsing
DatatypeSchema:parse(value: unknown) → T

Validates value and returns it, throwing on failure.

Errors

TypeDescription
"expected ..."Thrown when `value` is a different type

optional​

Wrapper
DatatypeSchema:optional() → OptionalSchema<T>

Wraps this schema so that nil is also accepted.

default​

Wrapper
DatatypeSchema:default(
fallback: T--

Value used when parsing nil

) → DefaultSchema<T>

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

defaultWith​

Wrapper
DatatypeSchema:defaultWith(
produce: () → T--

Builds the value used when parsing nil

) → DefaultSchema<T>

Like DatatypeSchema:default, but calls produce on every parse.

readonly​

Wrapper
DatatypeSchema:readonly() → ReadonlySchema<T>

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

writeonly​

Wrapper
DatatypeSchema:writeonly() → WriteonlySchema<T>

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

Show raw api
{
    "functions": [
        {
            "name": "safeParse",
            "desc": "Validates `value` without throwing.\n\t",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "source": {
                "line": 1880,
                "path": "src/init.luau"
            }
        },
        {
            "name": "parse",
            "desc": "Validates `value` and returns it, throwing on failure.\n\t",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "unknown"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "tags": [
                "Parsing"
            ],
            "errors": [
                {
                    "lua_type": "\"expected ...\"",
                    "desc": "Thrown when `value` is a different type"
                }
            ],
            "source": {
                "line": 1900,
                "path": "src/init.luau"
            }
        },
        {
            "name": "optional",
            "desc": "Wraps this schema so that `nil` is also accepted.\n\t",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "OptionalSchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1918,
                "path": "src/init.luau"
            }
        },
        {
            "name": "default",
            "desc": "Wraps this schema so that `nil` yields `fallback` instead of failing.\n\t",
            "params": [
                {
                    "name": "fallback",
                    "desc": "Value used when parsing `nil`",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1933,
                "path": "src/init.luau"
            }
        },
        {
            "name": "defaultWith",
            "desc": "Like [DatatypeSchema:default], but calls `produce` on every parse.\n\t",
            "params": [
                {
                    "name": "produce",
                    "desc": "Builds the value used when parsing `nil`",
                    "lua_type": "() -> T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DefaultSchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1950,
                "path": "src/init.luau"
            }
        },
        {
            "name": "readonly",
            "desc": "Wraps this schema so that a field using it is typed `read`.\n\t",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ReadonlySchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1964,
                "path": "src/init.luau"
            }
        },
        {
            "name": "writeonly",
            "desc": "Wraps this schema so that a field using it is typed `write`.\n\t",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "WriteonlySchema<T>"
                }
            ],
            "function_type": "method",
            "tags": [
                "Wrapper"
            ],
            "source": {
                "line": 1978,
                "path": "src/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "typeName",
            "desc": "The `typeof` name this schema accepts, such as `\"Color3\"`.\n\t",
            "lua_type": "string",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1837,
                "path": "src/init.luau"
            }
        },
        {
            "name": "isOptional",
            "desc": "Always `false`. Datatypes carry no `minimum` or `maximum`.\n\t",
            "lua_type": "boolean",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1847,
                "path": "src/init.luau"
            }
        },
        {
            "name": "access",
            "desc": "Always `\"readwrite\"`. Chain `:readonly()` or `:writeonly()` to change it.\n\t",
            "lua_type": "\"readwrite\"",
            "tags": [
                "Reflection"
            ],
            "readonly": true,
            "source": {
                "line": 1857,
                "path": "src/init.luau"
            }
        }
    ],
    "types": [],
    "name": "DatatypeSchema",
    "desc": "Validates a Roblox datatype by its `typeof` name, so a table that merely\ncarries the same fields is rejected — useful when the value arrived over a\nremote, where anything can be sent.\n\nReached through the named constructors rather than built directly:\n[Vet.color3] and [Vet.udim2] both return one of these.\n\n```lua\nlocal Tint = v.color3()\nlocal Size = v.udim2()\n\nTint:parse(Color3.new(1, 0, 0))      --> Color3(1, 0, 0)\nTint:parse({ R = 1, G = 0, B = 0 })  --> errors: expected Color3, got table\nSize:parse(UDim2.fromScale(1, 1))    --> UDim2\n```\n\nEach datatype schema holds no state beyond the name it checks, so the\nconstructors hand out one frozen shared instance rather than allocating.",
    "source": {
        "line": 1795,
        "path": "src/init.luau"
    }
}