How to defining Valibot schemas that agree with a TypeScript type? #377
-
Example from Zod
How can I achieve that in Valibot? |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Jan 20, 2024
Replies: 1 comment 9 replies
-
You can use import * as v from 'valibot';
type Player = {
name: string;
age?: number | undefined;
active: boolean | null;
};
export const Player = v.object({
name: v.string(),
age: v.optional(v.number()),
active: v.nullable(v.boolean()),
}) satisfies v.BaseSchema<Player>; |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
fabian-hiller
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
BaseSchema
: