We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import * as v from 'valibot'; const BoolWithUnion = v.pipe( v.union([v.literal('true'), v.literal('false')]), v.transform((x) => x === 'true'), ) const BoolWithFallbackUnion = v.fallback(BoolWithUnion, true); const BoolWithCheck = v.pipe( v.string(), v.check(x => ['true', 'false'].includes(x)), v.transform((x) => x === 'true'), ) const BoolWithFallbackCheck = v.fallback(BoolWithCheck, true); const NumWithUnion = v.pipe( v.union([v.string(), v.number()]), v.transform((x) => typeof x === 'string' ? parseInt(x) : x), ) const NumWithFallbackUnion = v.fallback(NumWithUnion, 42); const NumWithCheck = v.pipe( v.any(), v.check(x => typeof x === 'string' || typeof x === 'number'), v.transform((x) => typeof x === 'string' ? parseInt(x) : x), ) const NumWithFallbackCheck = v.fallback(NumWithCheck, 42); console.log(v.parse(BoolWithUnion, 'false'));// false console.log(v.parse(BoolWithCheck, 'false'));// false console.log(v.parse(BoolWithFallbackUnion, 'false'));// "false" should be false console.log(v.parse(BoolWithFallbackCheck, 'false'));// false console.log(v.parse(NumWithUnion, '42'));// 42 console.log(v.parse(NumWithCheck, '42'));// 42 console.log(v.parse(NumWithFallbackUnion, '42'));// "42" should be 42 console.log(v.parse(NumWithFallbackCheck, '42'));// 42
The text was updated successfully, but these errors were encountered:
Thank you! You found a bug! I will investigate this problem and check our unit tests.
Sorry, something went wrong.
Fix bug in fallback method for specific schemas #752
d8e43fc
v0.37.0 is available
fabian-hiller
No branches or pull requests
The text was updated successfully, but these errors were encountered: