Skip to main content

Typer

Strict typechecking in runtime implementation for Roblox.

Functions

Static

Typer.Static(
CallbackFunction(any?) → any?--

The wrapped function

) → StaticFunction

Wraps a function so that all parameters and return values are matched to the correct types.

local ExampleStaticFunction = Typer.Static(function(Foo : number, Bar : string)
	return `{Foo} and {Bar}`, {Foo = Foo, Bar = Bar}
end).WithParameterTypes("number", "string").WithReturnTypes("string", "table").Asserted()

local Value0, Value1 = ExampleStaticFunction(10, "Hello!") -- Does not error
local Value2, Value3 = ExampleStaticFunction({}, true) -- Errors

Cast

Typer.Cast(
Valueany--

The cast value

) → (...string)any--

The casting method

Checks if a value is of a certain type, allowing multiple types

local MyValue = "Hello, world!"

Typer.Cast(MyValue)("number", "string") -- No error
Typer.Cast(MyValue)("table") -- Error

CastEq

Typer.CastEq(
Value0any,--

The first value for comparison

Value1any--

The second value for comparison

) → boolean--

Whether the values are the same

Checks if two values are of the same type, and returns a boolean based on whether they are the same value as well.

local Value0 = Typer.CastEq(1, 2) -- No error
print(Value0) -- Prints "false"

local Value1 = Typer.CastEq("Foo", "Foo") -- No error
print(Value1) -- Prints "true"

local Value2 = Typer.CastEq(1, "Foo") -- Error

TupleAssertion

Typer.TupleAssertion(
...string--

The inputted types, in order

) → (...any)--

The function used to check arguments

Throws an error if inputted types do not match inputted argments in order.

Typer.TupleAssertion("number", "boolean", "string")(1, true, "Alo") -- No error
Typer.TupleAssertion("boolean", "table")(1, 2) -- Throws error

Expect

Typer.Expect(
...any--

The arguments to be checked

) → ExpectInstance--

The table of methods to be called back, each returning itself

A wrapper for Typer.TupleAssertion, allowing callbacks for different outcomes.

Typer.Expect(1, 2, 3).ToBe("number", "number", "number").AndIfNot(function()
	print("Uh oh!")
end).AndIfSo(function()
	print("Yay!")
end) -- Prints "Yay!"

Typer.Expect(true, false, true).ToBe("number", "number", "number").AndIfNot(function()
	print("Uh oh!")
end).AndIfSo(function()
	print("Yay!")
end) -- Prints "Uh oh!"

Env

Typer.Env() → Environment--

The created proxy table

Creates a proxy table that allows access to values stored in it, but does not allow edits to values already declared. It also can be called like a function with a command indicator. Commands are: DumpAll, DumpValue, PrintAll, PrintValue.

local Environment = Typer.Env()

Environment.Foo = 5
Environment.Bar = 10

print(Environment.Foo) -- Prints "5"
print(Environment.Bar) -- Prints "10"
print(Environment.DoesntExist) -- Prints nil and throws warning

Environment("DumpAll") -- Dumps all values, turning them to nil

Environment.Foo = 5

print(Environment.Foo) -- Prints "5"
print(Environment.Bar) -- Prints nil and throws warning

Environment.Foo = 10 -- Throws error since it already exists
Show raw api
{
    "functions": [
        {
            "name": "Static",
            "desc": "Wraps a function so that all parameters and return values are matched to the correct types.\n\n```lua\nlocal ExampleStaticFunction = Typer.Static(function(Foo : number, Bar : string)\n\treturn `{Foo} and {Bar}`, {Foo = Foo, Bar = Bar}\nend).WithParameterTypes(\"number\", \"string\").WithReturnTypes(\"string\", \"table\").Asserted()\n\nlocal Value0, Value1 = ExampleStaticFunction(10, \"Hello!\") -- Does not error\nlocal Value2, Value3 = ExampleStaticFunction({}, true) -- Errors\n```",
            "params": [
                {
                    "name": "CallbackFunction",
                    "desc": "The wrapped function",
                    "lua_type": "(any?) -> any?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "StaticFunction"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 24,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        },
        {
            "name": "Cast",
            "desc": "Checks if a value is of a certain type, allowing multiple types\n\n```lua\nlocal MyValue = \"Hello, world!\"\n\nTyper.Cast(MyValue)(\"number\", \"string\") -- No error\nTyper.Cast(MyValue)(\"table\") -- Error\n```",
            "params": [
                {
                    "name": "Value",
                    "desc": "The cast value",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "The casting method",
                    "lua_type": "(... : string) : any"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 84,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        },
        {
            "name": "CastEq",
            "desc": "Checks if two values are of the same type, and returns a boolean based on whether they are the same value as well.\n\n```lua\nlocal Value0 = Typer.CastEq(1, 2) -- No error\nprint(Value0) -- Prints \"false\"\n\nlocal Value1 = Typer.CastEq(\"Foo\", \"Foo\") -- No error\nprint(Value1) -- Prints \"true\"\n\nlocal Value2 = Typer.CastEq(1, \"Foo\") -- Error\n```",
            "params": [
                {
                    "name": "Value0",
                    "desc": "The first value for comparison",
                    "lua_type": "any"
                },
                {
                    "name": "Value1",
                    "desc": "The second value for comparison",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether the values are the same",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 112,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        },
        {
            "name": "TupleAssertion",
            "desc": "Throws an error if inputted types do not match inputted argments in order.\n\n```lua\nTyper.TupleAssertion(\"number\", \"boolean\", \"string\")(1, true, \"Alo\") -- No error\nTyper.TupleAssertion(\"boolean\", \"table\")(1, 2) -- Throws error\n```",
            "params": [
                {
                    "name": "...",
                    "desc": "The inputted types, in order",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "The function used to check arguments",
                    "lua_type": "(... any)"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 132,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        },
        {
            "name": "Expect",
            "desc": "A wrapper for Typer.TupleAssertion, allowing callbacks for different outcomes.\n\n```lua\nTyper.Expect(1, 2, 3).ToBe(\"number\", \"number\", \"number\").AndIfNot(function()\n\tprint(\"Uh oh!\")\nend).AndIfSo(function()\n\tprint(\"Yay!\")\nend) -- Prints \"Yay!\"\n\nTyper.Expect(true, false, true).ToBe(\"number\", \"number\", \"number\").AndIfNot(function()\n\tprint(\"Uh oh!\")\nend).AndIfSo(function()\n\tprint(\"Yay!\")\nend) -- Prints \"Uh oh!\"\n```",
            "params": [
                {
                    "name": "...",
                    "desc": "The arguments to be checked",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "The table of methods to be called back, each returning itself",
                    "lua_type": "ExpectInstance"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 167,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        },
        {
            "name": "Env",
            "desc": "Creates a proxy table that allows access to values stored in it, but does not allow edits to values already declared.\nIt also can be called like a function with a command indicator. Commands are: DumpAll, DumpValue, PrintAll, PrintValue.\n\n```lua\nlocal Environment = Typer.Env()\n\nEnvironment.Foo = 5\nEnvironment.Bar = 10\n\nprint(Environment.Foo) -- Prints \"5\"\nprint(Environment.Bar) -- Prints \"10\"\nprint(Environment.DoesntExist) -- Prints nil and throws warning\n\nEnvironment(\"DumpAll\") -- Dumps all values, turning them to nil\n\nEnvironment.Foo = 5\n\nprint(Environment.Foo) -- Prints \"5\"\nprint(Environment.Bar) -- Prints nil and throws warning\n\nEnvironment.Foo = 10 -- Throws error since it already exists\n```",
            "params": [],
            "returns": [
                {
                    "desc": "The created proxy table",
                    "lua_type": "Environment"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 229,
                "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Typer",
    "desc": "Strict typechecking in runtime implementation for Roblox.",
    "source": {
        "line": 6,
        "path": "src/Packages/_Index/miagobble_typer@0.1.1/typer/init.luau"
    }
}