Generic iteration type "V" causes issues when using "next" as an iterator in the new typechecker in strict mode

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.



Applied example:


(image so warnings show)
These warnings are the same as I showed above:
image

image

How to reproduce:

  1. Open up a script
  2. Type in the code example I showed above
  3. Hold v for autocomplete, replicates the behaviour I said about above
  4. See strict mode warnings

System info:

  • OS: Windows 11, version 24H2
  • Processor: 11th Gen Intel(R) Core™ i5-1135G7 @ 2.40GHz 2.42 GHz
  • 8GB RAM
  • Built-in GPU (idk sorry)

Expected behavior

Iteration variables should be correctly type’d.

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)
image

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