Issa - A runtime type validator with pretty errors and real types




A runtime type validator with pretty errors and real types

GithubWally PagePesde Page



Issa is in beta, expect bugs and API changes!

Features

  • Types from runtime checks

  • Pretty yet precise errors

  • Small, composable predicates

Installation

Wally

Add Issa to your wally.toml dependencies list:


[dependencies]

Is = "metatablesnow/issa@0.2.0"

Pesde

Add Issa to your pesde.toml dependencies list:


[dependencies]

Is = { name = "metatablesnow/issa", version = "0.2.0" }

Manual

Copy and paste the source code into a module script.

Guide

Every function in Is returns a Predicate.

local Is = require(path.to.Issa)

IsAge = Is.Number()

You can call a predicate:

local age = IsAge(18) -- This will pass, and return the input (18)
IsAge("Oops!") -- This will error

Try a predicate:

local success, data = IsAge:Try("Oops!")
-- success is false, and data is the error message

local success, data = IsAge:Try(18)
-- success is true, and data is the input (18)

Type a predicate:

type Age = typeof(IsAge.Type)
local bobsAge: Age = "Oops!" -- This will warn you!

use them to build more complex predicates:

local IsAnimal = Is.Interface({
    Name = Is.String(),
    Age = IsAge
})

or even refine them:

local IsAdult = Is.Refine(IsAnimal, function(self, animal)
    -- Refinements run last, so no need to check if this is a table!
    if animal.Age < 18 then
        return Is.Fail(animal, "number over 18", "animals age is under 18", animal, "Age", "field")
    end

    return Is.Pass()
end)

IsAdult(13) -- This will error!

9 Likes

Is this more versatile and robust than greentea? I dont see composite type examples in the OP for types like functions, structs, arrays etc

1 Like

in my opinion, issa is simpler to use than greentea, offers more features, and is built for the new type solver! issa includes nearly all of the composite types found in greentea/gaurd. while they aren’t documented yet, most of them are pretty straightforward.

2 Likes