Skip to content

misleading-lua-tuple-checks

Disallow using LuaTuple in conditional expressions.

In roblox-ts, a LuaTuple represents multiple return values from Luau. Using a LuaTuple directly in a conditional is almost always a bug. At runtime it’s an array, so the value is always truthy in JavaScript/TypeScript, even if the first Luau return value is false or nil.

This rule reports LuaTuple values in if, while, do...while, and for conditions, conditional expressions, logical expressions, and !tuple checks. It also reports declarations, assignments, and for...of bindings that keep the tuple as a single value instead of destructuring it.

The rule is fixable. For condition-style checks it adds [0]. For declarations, assignments, and for...of, it wraps the binding in array destructuring, for example const result = getTuple() becomes const [result] = getTuple().

It also handles IterableFunction types that yield LuaTuple values in for...of loops.

  1. Pick the value you want to test. If you only care about the first return value, use [0].
  2. Destructure when you keep the result. Write const [success, data] = getTuple() instead of storing the whole tuple.
  3. Check the destructured value. Use if (success) { ... } or another explicit check.
  4. Do the same in for...of. If the iterable yields tuples, destructure each item as it comes out.
Incorrect

A tuple value is always truthy, even when the first return value is falsey.

const result = getLuaTuple();
// ❌ Always true! Even if the first return is false.
if (result) {
print("This always prints");
}
Correct

Destructure and check the specific value you care about.

// ✅ Destructuring (Recommended)
const [success, data] = getLuaTuple();
if (success) {
print("Action succeeded");
}
// ✅ Explicit indexing
if (getLuaTuple()[0]) {
print("Value exists");
}

Runtime Mismatch

LuaTuple is a JavaScript array at runtime, so a truthiness check does not match Luau’s first-value behavior.

Silent Failures

Code can take the wrong branch and keep running without an obvious error.

Type Clarity

Destructuring makes it clear which tuple value you are actually using.