When iterating in the new typechecker, no matter what, the value field in the iteration always ends up being this type “V”. This causes the typechecker to freak out when using strict mode. This only happens when using next as an iterator.
here’s an example:
--!strict
--I used tables as they are the closest to instances, which I am experiencing the issue with
--this does also happen for this example though
local tbl = {
{3, 5, 7},
{5, 2, 1},
{2, 6, 3}
}
for i, v in next, tbl, nil do
v --> when holding "v" for autocomplete, it comes as "V"
v.someKey = 3 --> "Cannot add field 'someKey' to table V"
end
for i, v: {number} in next, tbl, nil do
v --> when holding for autocomplete now, v does show as {number}
v.someKey = 3 --> "Cannot add field 'someKey' to table V"
end
This does not only happen for array-like data structures, but also dictionaries. It also only happens when I use the next iterator. No matter what type annotation methods I use, for example on the table as well, the warning still shows.
I’d like to add on that this issue also does not happen for custom iterators, just how it does not happen for other iterators like the return values of pairs and ipairs:
local function simpleArrayIterator(iterable: {any}): (number, any) --simple iterator to show example
assert(type(iterable) == "table", "Expected table as parameter to 'simpleIterator'")
local index = 0
local count = #iterable
return function()
index += 1
if index <= count then
return index, iterable[index]
end
end
end
(incorrectly used here but i tested with correct use and issue is still there)
The warning also does not show up with a manual type cast.
for _, track: AnimationTrack in next, tracks, nil do
track.Priority = Enum.AnimationPriority.Action --example
--"Field 'Priority' could not be added to table 'V'"
track = track :: AnimationTrack
track.Priority = Enum.AnimationPriority.Action --no warning
end
Hey there, thank you for the report! The bugs you’ve reported in the New Type Solver should be fixed now in that e.g.
for i, v in next, tbl, nil do
print(v) -- v has the type `{number}` here without annotation
end
The errors about adding a field to the array persist because they’re correct, the array does not already have a property named someKey, so you get a type error telling you that you cannot assign to someKey. Likewise, code like the following with instances should also work correctly now:
local tracks: {AnimationTrack} = {}
for _, track in next, tracks, nil do
track.Priority = Enum.AnimationPriority.Core -- no error
end
Please don’t hesitate to open any new bug reports with other issues you encounter! Cheers!