Codectionary / Developer documentation / Luau

Luau generic type packs

Type packs describe lists of parameter or return types. A generic pack can preserve heterogeneous return values; it differs from a variadic pack whose elements share one type.

Syntax

local function forward<T...>(...: T...): T...

Examples

Luau generic type packs

Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.

--!strict
local function forward<T...>(...: T...): T...
    return ...
end
local name, score = forward("Ada", 7)
print(string.upper(name))
print(score + 1)
  1. Output: ADA, then 8. The pack preserves string and number at separate positions rather than collapsing them into one type.

Best practices

  • Use T... for heterogeneous generic packs and ...T for repeated values of one type. Preserve final-position return expansion when forwarding.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading