zod, a runtime validation library, has an intuitive & statically typed dx that exposes possible errors at the type level
import { z } from "zod";
const User = z.object({ username: z.string(), password: z.string() });
const user = User.safeParse({ username: 123, password: 'secret' });
const usernameFailed: boolean = !user.success
&& !!user.error.format().username
// ^
// this is statically typed!
Current Behavior
const User = D.fromStruct({ username: D.string, password: D.string })
const user = decoder.decode({ username: 123, password: 'secret' })
const usernameFailed: boolean = pipe(
user,
E.fold(
(e) => D.draw(e).includes('username'),
() => false, // ^
) // |
// have to look at the implementation of 'struct' to know this
) // could overlap with other errors
This approach is useful for displaying error messages (e.g. on forms), suggesting possible solutions, and/or recovering automatically from malformed input
Describe alternatives you've considered
A fork, or even a separate library (io-ts-validation?)
🚀 Feature request
zod, a runtime validation library, has an intuitive & statically typed dx that exposes possible errors at the type level
Current Behavior
Desired Behavior
Suggested Solution
A non empty array of a 'sum type' of errors
A bit clunky, but maximizes compile-time information
partial implementation (playground)
Who does this impact? Who is this for?
This approach is useful for displaying error messages (e.g. on forms), suggesting possible solutions, and/or recovering automatically from malformed input
Describe alternatives you've considered
A fork, or even a separate library (
io-ts-validation
?)Additional context
Your environment