Incorret t compilation with flamework
const test_guard = Flamework.createGuard<[string, ...unknown[]]>();
warn("[RESULT]", test_guard(["test", 123, "hi"])); //fails
const test_guard = Flamework.createGuard<[string, ...unknown[]]>();
warn("[RESULT]", test_guard(["test", 123, "hi"])); //fails
local test_guard = Flamework.createGuard(t_1.strictArray(t_1.string, t_1.union(t_1.any, t_1.none)))
local test_guard = Flamework.createGuard(t_1.strictArray(t_1.string, t_1.union(t_1.any, t_1.none)))
1 Reply
function t.strictArray(...)
local valueTypes = { ... }
assert(t.array(t.callback)(valueTypes))
return function(value)
local keySuccess = arrayKeysCheck(value)
if keySuccess == false then
return false
end
-- If there's more than the set array size, disallow
if #valueTypes < #value then
return false
end
for idx, typeFn in pairs(valueTypes) do
local typeSuccess = typeFn(value[idx])
if not typeSuccess then
return false
end
end
return true
end
end
function t.strictArray(...)
local valueTypes = { ... }
assert(t.array(t.callback)(valueTypes))
return function(value)
local keySuccess = arrayKeysCheck(value)
if keySuccess == false then
return false
end
-- If there's more than the set array size, disallow
if #valueTypes < #value then
return false
end
for idx, typeFn in pairs(valueTypes) do
local typeSuccess = typeFn(value[idx])
if not typeSuccess then
return false
end
end
return true
end
end