Are there negation types/operators? #926
-
Is there something like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There isn't a concept of const optionalNonEmptyString = z.string().min( 1 ).optional()
type OptionalNonEmptyString = z.infer<typeof optionalNonEmptyString>
// type OptionalNonEmptyString = string | undefined
console.log( optionalNonEmptyString.safeParse( 'foo' ).success ) // true
console.log( optionalNonEmptyString.safeParse( undefined ).success ) // true
console.log( optionalNonEmptyString.safeParse( '' ).success ) // false For other schemas that you want to use not, you could do something using refine. |
Beta Was this translation helpful? Give feedback.
There isn't a concept of
xor
ornot
that I know of, but you could do your example as shown below:For other schemas that you want to use not, you could do something using refine.