Closed issam-seghir closed 7 months ago
You can't pass an errorMap to refine normally.
const schema = z.string().refine( ( x ): x is string => true, {
errorMap: () => ( { message: 'This is a custom error message' } )
// ^^^^^
// Object literal may only specify known properties, and 'errorMap' does not exist in type 'Partial<Omit<ZodCustomIssue, "code">>...
} )
Please pass the errorMap to z.string instead as is shown below and in the docs:
https://github.com/JacobWeisenburger/zod_utilz#makeerrormap
const errorMap = zu.makeErrorMap( {
custom: ( err ) => `${ err.data } is not a valid port number. Must be a number between 0 and 65536`,
} )
const schema = z.string( { errorMap } )
If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 https://github.com/sponsors/JacobWeisenburger