I am not using the new Luau Type Solver!
Storing metatable types with generics in tables, then iterating through them and running them, produces a false type warning. For example:
--!strict
local SomeGenericClass = {}
SomeGenericClass.__index = SomeGenericClass
type SomeGenericClass<Class> = typeof(setmetatable({}:: {
_Object: Class,
}, SomeGenericClass))
function SomeGenericClass.SomeGenericMethod<Class>(self: SomeGenericClass<Class>)
self:SomeGenericMethod()
end
----------------------------------------------------------------------------------------------------
-->> warning
local arrayWithGenericClass: {SomeGenericClass<Frame>} = {}
for _, Class in arrayWithGenericClass do
Class:SomeGenericMethod() --> warns (warning below)
--[[
Type Error: Type 'SomeGenericClass' could not be converted into
'SomeGenericClass' caused by: Type 'SomeGenericClass' from
'game.Workspace.Script' could not be converted into'SomeGenericClass'
from 'game.Workspace.Script' caused by: Property 'SomeGenericMethod'
is not compatible. Type '(SomeGenericClass) -> ()' could not be
converted into '<Class>(SomeGenericClass) -> ()'; different number
of generic type parameters
]]
end
-->> no warning
local ExplicitDefinition: SomeGenericClass<Frame> = setmetatable({
_Object = Instance.new("Frame"),
}, SomeGenericClass)
ExplicitDefinition:SomeGenericMethod() --> accessing explicit definitions are fine
arrayWithGenericClass[1]:SomeGenericMethod() --> accessing using indexing is fine
----------------------------------------------------------------------------------------------------
Expected behavior
No warning, since it’s a valid action.