A collection of composable type validators that help enforce runtime type safety.
Golem is the combination of t and Guard
-- The value need to be typed manually for Golem.Struct (waiting for new type-solver)
local check = Golem.Check(Golem.Struct({
test = Golem.String :: string,
instance = Golem.InstanceOf("Workspace") :: Workspace
}))
check({
test = "a",
instance = workspace
}) -- will passlocal check = Golem.Check(Golem.Struct({
test = Golem.String :: string,
instance = Golem.InstanceOf("Workspace") :: Workspace
}))
-- Since `game` is not `workspace`, the following check with error.
check({
test = "a",
instance = game
})local safeCheck = Golem.SafeCheck(Golem.Tuple(
Golem.Optional(Golem.String),
Golem.Or(Golem.String, Golem.Number)
))
local ok, errorMessage = safeCheck(nil, 10)
print(ok, errorMessage) -- Will print (true, nil)
local ok, errorMessage = safeCheck(nil, true)
print(ok, errorMessage) -- Will print (false, "Excepted string, got boolean OR Excepted number, got boolean")