function f(vector: Vector3)
for i, member in next, {'X', 'Y', 'Z'} do
local v = vector[member]
--> Expected type table, got 'Vector3' instead
end
end
This happens for all non-table objects. The only workaround is to re-cast the object as any
or as a table with the appropriate members for that specific read, e.g. v = (vector::any)[member]
, which is gross.
Luau should try to statically resolve the possible values and then warn if something is incorrect. For example, the above code would be okay but if I added a 'W'
to the table it would warn me that not all the possible iterations will satisfy the type checker since vector
has no W
key.
If it can’t statically resolve the values it should try resolving the types. For example, the above code would work but if I added a 100
to the table it would warn me that vector
only has string
keys and not all iterations would function correctly.