Skip to content

JSDoc for schema and inferred type #841

Discussion options

You must be logged in to vote

After digging into this some more, I'm pretty sure that not being able to see the JSdoc after z.infer is a problem with typescript and I don't think there is anything Zod can do to fix that.

const UserSchema = z.object( {
    /** UTC ISO date time string */
    createdAt: z.string()
} )
typeof UserSchema.shape[ 'createdAt' ]
// when you hover over 'createdAt' then the popup shows the JSdoc
// (property) createdAt: z.ZodString
// UTC ISO date time string

type CreatedAt = typeof UserSchema.shape[ 'createdAt' ]
// but unfortunately, when you make a type alias, it loses the JSdoc
//-> CreatedAt = z.ZodString

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@the-spyke
Comment options

@JacobWeisenburger
Comment options

@the-spyke
Comment options

@JacobWeisenburger
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by the-spyke
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