Skip to content

Types for helper functions for working with schemas? #883

Discussion options

You must be logged in to vote

I can't figure out why you are getting that error. But if you are wanting to do some preprocessing I would recommend using z.preprocess

const schema = z.object( {
    foo: z.string(),
    bar: z.literal( 'bar' ),
} )
type Schema = z.infer<typeof schema>
// type Schema = {
//     foo: string
//     bar: "bar"
// }

const preprocessedSchema = z.preprocess( input => {
    const processedInput = ... // some pre-processing omitted
    return processedInput
}, schema )
type PreprocessedSchema = z.infer<typeof preprocessedSchema>
// type PreprocessedSchema = {
//     foo: string
//     bar: "bar"
// }

Replies: 1 comment 1 reply

Comment options

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

Answer selected by msakrejda
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