arktype
arktype copied to clipboard
Branded Types
Request a feature
🤷 Motivation
What problem are you having?
In applications having Branded types improves some of the confidence around our code base. We can parse a user email at the edge of the application, brand that with a symbol, and then in components, assume the string we have is indeed a valid email.
// in Zod
const Email = z
.string()
.refine(isEmail)
.brand<"Email">();
Why should we prioritize solving it?
This would be one less hurdle for people moving from zod
or io-ts
to arktype
.
💡 Solution
How do you think we should solve the problem?
Given the Arktype beta
future looking toward chaining, perhaps:
const Email = type('string')
.morph(isEmail)
.brand("Email");
Why do you think this is the best solution?
Im not highly confident it is. How would with work in the parseOperator
...?