3 ms·
I'm using zod to do the same. If you aren't using fp-ts it will fit a lot easier into your ecosystem.
by fy20 6y ago
I'm using zod to do the same. If you aren't using fp-ts it will fit a lot easier into your ecosystem.
- samhh 6y agoYou don't really need to be bought into fp-ts to use io-ts. Just create a helper function that morphs the native decode output, `Either<E, A>`, to something like `E | A` or `A | null`.
- eyelidlessness 6y agoOr even `asserts value is A` if error handling is more your cup of tea/more idiomatic in your project.
- resynth1943 6y agoI use runtypes: import { Record, Number, Static } from 'runtypes'; export const Thing = Record({ thing: Number }); export type Thing = Static<Thing>; Then you can import it like this: import { Thing } from './thing'; function (thing: Thing) { if (Thing.guard(thing)) { console.log('we have a thing!'); } }