-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
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
Calling isOptional()
on a coerce.bigint
throws an error
#1911
Comments
Kind of related to the following: I can't really see the benefit of why try {
return BigInt( value )
} catch ( error ) {
ctx.addIssue( {
code: 'invalid_type',
expected: 'unknown',
received: value,
message: `Can't be parsed to BigInt`,
} )
} |
I added an easier way to work with coerce to my utilz library. Perhaps this will help you. https://github.com/JacobWeisenburger/zod_utilz#coerce import { zu } from 'zod_utilz'
const bigintSchema = zu.coerce( z.bigint() )
console.log( zu.SPR( bigintSchema.safeParse( undefined ) ).error?.issues )
// [
// {
// code: 'invalid_type',
// expected: 'bigint',
// received: 'undefined',
// path: [],
// message: 'Required'
// }
// ]
const isOptional = bigintSchema.isOptional() // no ts error
console.log( isOptional ) // false, as expected |
@marcus13371337 |
Yes, I was able to get around the problem by creating a custom bigint-schema. But I don't see why |
same about const f = z.coerce.bigint();
f.isNullable(); despite the fact that I think the confusion comes from the expectation that coerce is expected to be fail safe. |
Try the following code:
That code should be able to run IMO, but now it throws an error,
TypeError: Cannot convert undefined to a BigInt
The text was updated successfully, but these errors were encountered: