How to get meta from a refinement? #5337
-
|
const mySchema = zod.meta({ "test": 123}).refine(...) How can I get "test" from mySchema above? Note: I can't touch the schema definition. All I have is mySchema variable. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Hi @beratbayram! I'm Dosu and Iβm helping the zod team. You can get the meta value from your schema instance by calling If you have any follow-up questions, feel free to ask! If this solves your issue, please close the thread. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report π | OtherΒ Β |
Beta Was this translation helpful? Give feedback.
-
|
As it's specified in the documentation:
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(); // => undefinedBecause of this, you can't access metadata after refinement. Same for This is described in the I know you said that you can't change the schema definition, but in general, you should move calling |
Beta Was this translation helpful? Give feedback.
As it's specified in the documentation:
With this example given:
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 β¦