@flect/guard
v4.2.0
Published
Typeguards for flect types
Downloads
7
Maintainers
Readme
Introduction
Flect/guard is a library for validating that arbitrary JavaScript objects conform to a Flect type.
Usage
const Animal = record({
legCount: numberType,
sound: stringType
});
type Animal = Reify<typeof Animal>;
const v = new GuardChain();
const recV = new RecordValidator(v);
v.add(defaultGuards);
v.add(recV);
const maybeAnimal: unknown = {legCount: 3, sound: "woof"};
const animalGuard = v.get(Animal)!;
if (animalGuard(maybeAnimal)) {
console.log(maybeAnimal.sound); // Goes 'woof'
}