Add proper support for varargs to typed Lua

As a Roblox developer, it is currently annoying to have a part of the language outright impossible to represent in typed Lua. Varargs are used in a multitude of functions, ranging from core functions (print, string.format, table.pack/table.unpack, warn etc.) to Roblox’s API (BindableEvent.Fire). These functions are currently impossible to type correctly in Typed Lua, leading to strange warnings like this:

image

I try to avoid using varargs where possible, but I cannot avoid them completely in Roblox because of how they show up in built-in functions. When I do use them, they are not type safe, which can and will lead to bugs.

I’m unsure how Roblox gets around this problem with functions like print and warn, but with ones like string.char, it defines a set number of arguments, which is… Bad.
image

Proper support for varargs in typed Lua must be added. What form that takes is ultimately up for debate, but I suggest ...: type. It isn’t pretty, but it’s consistent with the rest of the type syntax.

5 Likes