Skip to content
Discussion options

You must be logged in to vote

I would rewrite your schema. See this playground.

import * as v from 'valibot';

const Schema = v.union([
  v.pipe(v.string(), v.transform(parseInt)),
  v.optional(v.number(), 0),
]);

Another option is to use the fallback method instead of the optional schema, but the behavior is different. See this playground.

import * as v from 'valibot';

const Schema = v.fallback(v.pipe(v.string(), v.transform(parseInt)), 0);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ha1fstack
Comment options

Answer selected by fabian-hiller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants