news-2021-06-30-luau-recap-june-2021.md
June 30, 2021
Most of our team was busy working on improving Luau interaction with Roblox Studio for an upcoming feature this month, but we were able to add typechecking and performance improvements as well!
To improve type inference under conditional expressions and other dynamic type changes (like assignments) we have introduced a new constraint resolver framework into Luau type checker.
This framework allows us to handle more complex expressions that combine and/not operators and type guards.
Type guards support include expressions like:
if instance:IsA("ClassName") thenif enum:IsA("EnumName") thenif type(v) == "string" thenThis framework is extensible and we have plans for future improvements with a == b/a ~= b equality constraints and handling of table field assignments.
It is now also possible to get better type information inside else blocks of an if statement.
A few examples to see the constraint resolver in action:
Please note that constraints are currently placed only on local and global variables. One of our goals is to include support for table members in the future.
We have improved the way we handled module require calls. Previously, we had a simple pattern match on the local m = require(...) statement, but now we have replaced it with a general handling of the function call in any context.
Handling of union types in equality operators was fixed to remove incorrect error reports.
A new IsA method was introduced to EnumItem to check the type of a Roblox Enum. This is intended to replace the enumItem.EnumType == Enum.NormalId pattern in the code for a construct that allows our constraint resolver to infer better types.
Additional fixes include:
table.pack return type was fixedtable? type. While you add a check for nil, typechecking can continue with better type information in other expressions.If you have Luau-Powered Type Hover beta feature enabled in Roblox Studio, you will see more function argument names inside function type hovers.
We no longer allow referencing a function by name inside argument list of that function:
local function f(a: number, b: typeof(f)) -- 'f' is no longer visible here
As always, we look for ways to improve performance of your scripts:
table.move has been greatly improved