← Luau typing quick reference

Type casts with ::

Luau 0.731 · --!strict
expression :: Type

The :: operator tells the analyzer to treat an expression as a compatible type. It does not validate external data or change the runtime value.

When to use it

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

  • Use :: only when you know more than inference can prove.
  • A cast is not a runtime validator and should not be used to silence a real mismatch.

Focused example

--!strict

type Color = "red" | "green"

local raw = "red"
local selected = raw :: Color

-- Validate unknown storage or server data with luastra/data
-- before casting it to a trusted application type.

Complete inventory

View all pages in Luau typing quick reference
← Previous: any, unknown, and neverNext: Runtime immutability with table.freeze →