Unions and type narrowing
Luau 0.731 · --!strictA | B
A value may match either type. A type, typeof, nil, or tag check narrows the union to a safe branch.
When to use it
Read this page when you need to apply Unions and type narrowing, verify its exact contract, and adapt the example without bypassing validation or host boundaries.
Focused example
--!strict
local value: string | number = "hello"
local description: string
if type(value) == "string" then
description = string.upper(value)
else
description = tostring(value + 1)
end
assert(description == "HELLO")