You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the or operator allows some idioms for default value.
local t1: {string:number} = { foo = 42 }
for _, v in pairs(t1) do
print(v * v)
end
local t2: {string:number} = { foo = 42 }
for _, v in pairs(t2 or {}) do
print(v * v)
end
for _, v in pairs(t1 or t2) do
print(v * v) -- ERROR: cannot use operator '*' for types B (unresolved generic) and B (unresolved generic)
end
for _, v in pairs((t1 or t2) as {string:number}) do -- workaround with a cast
print(v * v)
end
local function foo(a: number)
a = a or 1 -- the most known idiom
print(a * a)
end
foo(2)
The text was updated successfully, but these errors were encountered:
the
or
operator allows some idioms for default value.The text was updated successfully, but these errors were encountered: