valibot
valibot copied to clipboard
Is there a way to get the metadata as type?
I want to do something like this:
const UserSchema = v.pipe(v.object({
email: v.pipe(v.string(), v.email()),
password: v.pipe(v.string(), v.minLength(8)),
}),
v.title('user')
);
type UserTitle = v.InferMeta<typeof Schema, 'title'>
// UserTitle = 'user'
We do not have a utility type for this yet, but this should work. Check it out in our playground.
import * as v from 'valibot';
const UserSchema = v.pipe(
v.object({
email: v.pipe(v.string(), v.email()),
password: v.pipe(v.string(), v.minLength(8)),
}),
v.title('user'),
);
type UserTitle = Extract<
(typeof UserSchema)['pipe'][number],
{ type: 'title' }
>['title'];