Luau Recap: November 2022

They’re planning to support this in the future, but for now what you can do is add an assert after the guard clause.

E.g:

local function x( thing: string | number )
      if ( type( thing ) == "number" ) then return end
      assert( type( thing ) == "number" ) -- Errors the code if it's a number...
                   -- but it can never be a number because it returns beforehand.

      print( #thing ) -- No more warning!
end
2 Likes