osyrisrblx / t

A Runtime Typechecker for Roblox
MIT License
210 stars 39 forks source link

Roblox has built in type checking making this kinda useless #105

Closed walksanatora closed 2 years ago

walksanatora commented 2 years ago

as defined in the luau documentation the language actually has built in type checking https://luau-lang.org/typecheck

walksanatora commented 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
OverHash commented 2 years ago

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.

osyrisrblx commented 2 years ago

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: