"" (empty string),
NaN values will cause the assertion to fail in addition to
The reason for this is so that we can take advantage of TypeScript's
asserts value predicate feature.
Because of this change,
assert("") will cause an error in roblox-ts, but not in Luau.
Unfortunately, TypeScript already has an operator named "typeof" in the form of
typeof x. Because of this, we cannot expose the Luau
typeof() function directly. To get around this, we compile
Checking types with
typeOf is usually not very useful with roblox-ts unless you need the string value that is returned. This is because TypeScript cannot infer that your if-statement confirmed the value was type checked:
To get around this,
typeIs(value, "type") compiles to
typeof(value) == "type" and helps TypeScript infer the value was type checked:
classIs(value, "ClassName") compiles to
value.ClassName == "ClassName". This is useful for cases where you might want to avoid
pcall is available, it returns the type
LuaTuple<[false, string] | [true, T]> which is difficult to use!
The problem here is that
valueOrError are not linked after the destructure happens. You can avoid destructuring the result, but that makes things very hard to read.
To get around this, you can use
opcall which works the same as
pcall, but returns an object instead of the
identity macro compiles to just the inner value you pass into it, allowing for a zero-cost type constraint abstraction. This is useful for verifying that a given value is the type you expect: