luau
luau copied to clipboard
Tables with type parameters are not assignable to {[K]:V} in new solver strict mode
As of version 0.642, table types with fields being a generic type are incompatible with the table type {[K]:V} in the new solver, causing type errors when passed to functions such as next, table.create or table.isfrozen. This only appears to occur in strict mode.
--!strict
type genericTable<T> = {type:T}
local function nop<K,V>(t:{[K]:V}): () end
local t:genericTable<'any'> = {type = 'any'}
nop(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
table.clear(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
table.isfrozen(t) --Type 'genericTable<"any">' could not be converted into '{ [K]: V }'
next(t) --Type Error: (9,6) Type 'genericTable<"any">' could not be converted into '{+ [K]: V +}'