When using strict type checking (--!strict
), I encounter this weird type error:
This is the code:
function dictionary.find_key<K, V>(dict: Dictionary<K, V>, value: V): K?
for k, v in pairs(dict._data) do
if v == value then -- TypeError here
return k
end
end
return nil
end
I do not understand what this means, it seems that it fixes the problem if I ditched the type paramaters and just use any
type, which I dislike:
function dictionary.find_key(dict: Dictionary<any, any>, value: any): any?
Is there any way to fix this without removing the type paramaters?