← Luau typing quick reference

any, unknown, and never

Luau 0.731 · --!strict
any · unknown · never

any largely disables checking, unknown requires narrowing before use, and never describes an impossible value.

When to use it

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

  • Prefer a concrete type whenever possible.
  • Use unknown at untrusted boundaries and narrow it before use.
  • Keep any as a temporary escape hatch for code that cannot yet be typed.
  • Use never to prove that every union alternative was handled.

Focused example

--!strict

local value: unknown = "green"

if type(value) == "string" then
    local upper = string.upper(value)
end

local function impossible(value: never): never
    error("Unhandled value: " .. tostring(value))
end

Complete inventory

View all pages in Luau typing quick reference
← Previous: IntersectionsNext: Type casts with :: →