← Luau typing quick reference

Generics

Luau 0.731 · --!strict
Type<T> · function name<T>(value: T)

A type parameter lets one checked pattern work with many value types without losing their exact result type.

When to use it

Read this page when you need to apply Generics, verify its exact contract, and adapt the example without bypassing validation or host boundaries.

Focused example

--!strict

type Color = "red" | "green" | "blue"
type Result<T> =
    { success: true, value: T }
    | { success: false, error: string }

local function first<T>(items: {T}): T?
    return items[1]
end

local color: Color? = first({ "red" :: Color, "green" :: Color })
local score: number? = first({ 10, 20, 30 })

Complete inventory

View all pages in Luau typing quick reference
← Previous: Tagged unionsNext: Function types →