Add runtime type inspection for luau types

As a Roblox developer, it is currently very annoying to do runtime typechecking.

Most developers either do one of two things:

  1. Use if statements and error (or use assert) if a typeof call doesn’t match what we expect
  2. Use a runtime type checking library like t (GitHub - osyrisrblx/t: A Runtime Typechecker for Roblox)

In Luau, we have a well-established way to define types. It would be nice if there was a way to re-use those types during runtime type-checking (e.g. with a special function that takes in a variable and a Luau type definition), instead of having to manually re-define our types every time we wanted to do runtime type checking.

12 Likes

Luau types can’t be passed to a function, they aren’t values. For something like that a keyword would make more sense

local function a(x)
	assert(_ISTYPE(x,number))
	-- _ISTYPE ( <exp> , <type> )
	return x+1
end

or another operator

local function a(x)
	assert(x???number)
	-- <exp> ??? <exp>
	-- precedence should be just above the logical operators
end
1 Like