← Luau typing quick reference

Enum-like singleton unions

Luau 0.731 · --!strict
type Color = "red" | "green"

A union of literal strings limits a value to known alternatives. A separate frozen table can provide convenient runtime constants.

When to use it

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

  • Color exists only for the analyzer.
  • Colors is a runtime table containing named constants.

Focused example

--!strict

type Color = "red" | "green" | "blue"

local selected: Color = "green"
-- selected = "yellow" -- type error

local Colors: { Red: Color, Green: Color, Blue: Color } = {
    Red = "red",
    Green = "green",
    Blue = "blue",
}

table.freeze(Colors)

Complete inventory

View all pages in Luau typing quick reference
← Previous: Record typesNext: Optional values →