Type refinement

Narrowing a value's type inside a branch by checking it, for example with typeof or ==.

Think of it as Opening the jar and looking before you trust the label.

After if typeof(x) == "number" then, the checker treats x as a number inside that branch. Comparisons with string literals, ~= nil and IsA calls refine too. Refinement is how code turns an unknown value from a remote, a DataStore or an attribute into a known type safely.

Official reference: luau.org

Related terms