Closed walksanatora closed 2 years ago
so your example could be written in plain luau as
local function foo(a:string, b:number, c:string|nil)
assert(fooCheck(a, b, c))
-- you can now assume:
-- a is a string
-- b is a number
-- c is either a string or nil
end
foo() <-- script errors with a type error at parse phase
foo("1", 2)
foo("1", 2, "3")
foo("1", 2, 3) <--also a error during parse
Right, but that doesn't help with functions that are ran with unknown data. E.g., remote events. A large portion of roblox-ts users use t
, and they've had typechecking for years.
OverHash is correct. Static types do not exist at runtime, they are imperfect "guard rails" for your code (but still extremely useful!)
You can think of t
as a supercharged typeof(X) == "Y"
. It's useful for:
Foo | Bar
as defined in the luau documentation the language actually has built in type checking https://luau-lang.org/typecheck