Closed kenhuang closed 3 months ago
Yes, please try out BaseSchema
:
import * as v from 'valibot';
type Test {
field1?: string,
field2?: string,
}
const TestSchema: v.BaseSchema<Test> = v.object({
field1: v.optional(v.string()),
field2: v.optional(v.string()),
});
Hint: Sometimes satisfies
is better to not lose type safety for specific object related information:
import * as v from 'valibot';
type Test = {
field1?: string,
field2?: string,
}
const TestSchema = v.object({
field1: v.optional(v.string()),
field2: v.optional(v.string()),
}) satisfies v.BaseSchema<Test>;
Hey @fabian-hiller,
Base schema requires 3 generics arguments, so the provided example doesnt work.
Since we rewrote the whole library with v0.31.0, our implementation changed a bit. Just change BaseSchema
to GenericSchema
.
import * as v from 'valibot';
type Test = {
field1?: string,
field2?: string,
}
const TestSchema = v.object({
field1: v.optional(v.string()),
field2: v.optional(v.string()),
}) satisfies v.GenericSchema<Test>;
Thanks, I will give a try.
In zod we can do this:
Is anything similar in valibot? Thanks for the awsome library!