I’m learning to work with the type solver and attempting to create a filter function to filter table types. However, I’m getting type system errors and can’t grasp how to properly implement this approach.
--!strict
type function filter(t: type, m: type)
if not (t:is("table") and m:is("function")) then
error("nah")
end
local filtered = nil
for k, v in t:properties() do
if not m:returns().tail then continue end
if filtered then
filtered = types.intersectionof(filtered,
types.newtable({k = v}))
else
filtered = types.newtable({k = v})
end
end
return if filtered then filtered else types.singleton(nil)
end
type function sorter(k: type, v: type)
return types.singleton(k:value() == "oliver")
end
local a = {
jason = 12.5,
jack = "roblox",
oliver = 50
}
local b: filter<typeof(a), sorter> = {
oliver = 50
}
