Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
Discussion options

You must be logged in to vote

As it's specified in the documentation:

Metadata is associated with a specific schema instance. This is important to keep in mind, especially since Zod methods are immutableβ€”they always return a new instance.

With this example given:

const A = z.string().meta({ description: "A cool string" });
A.meta(); // => { description: "A cool string" }

const B = A.refine(_ => true);
B.meta(); // => undefined

Because of this, you can't access metadata after refinement. Same for .superRefine(), and .check().

This is described in the .meta() documentation.

I know you said that you can't change the schema definition, but in general, you should move calling .meta() to after the refinement so it stays …

Replies: 2 comments 2 replies

Comment options

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

Comment options

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

Answer selected by beratbayram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants