Currently it's typed as returning ReadonlyArray<[Entity<T>, ...T]>, but the return value actually has an __iter metamethod that interferes with things.
The metamethod lets you do this in Lua (the same as iterating a query without snapshotting it):
for entityId, health, player in world:query(Health, Player):snapshot() do
But in TS if we do something like .snapshot().mapFiltered(([id, health, player]) => {}), we'll generate something like:
local callback = function(_param)
local id = _param[1]
local cpn = _param[2]
local player = _param[3]
end
-- ▼ ReadonlyArray.mapFiltered ▼
local _newValue = {}
local _length = 0
for _k, _v in querySnapshot do
local _result = _arg0(_v, _k - 1, querySnapshot)
if _result ~= nil then
_length += 1
_newValue[_length] = _result
end
end
-- ▲ ReadonlyArray.mapFiltered ▲
And because of __iter, _k will end up being the id instead of the index and _v will be health, not [id, health, player], and so the callback will not get the value that the types think it will
Currently it's typed as returning
ReadonlyArray<[Entity<T>, ...T]>, but the return value actually has an__itermetamethod that interferes with things.The metamethod lets you do this in Lua (the same as iterating a query without snapshotting it):
But in TS if we do something like
.snapshot().mapFiltered(([id, health, player]) => {}), we'll generate something like:And because of
__iter,_kwill end up being the id instead of the index and_vwill be health, not[id, health, player], and so the callback will not get the value that the types think it will