Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.describe() is not wrapping, but creates a "new" _def #3832

Open
hco opened this issue Nov 4, 2024 · 0 comments
Open

.describe() is not wrapping, but creates a "new" _def #3832

hco opened this issue Nov 4, 2024 · 0 comments

Comments

@hco
Copy link

hco commented Nov 4, 2024

Hey there 👋

I've regularly hoped for some kind of "metadata" in zod, but read a lot of discussion about why it's not needed.

In my case, I just need to be able to identify some of my own schemas.
I do this by comparing someSchema._def with mySchema._def, unwrapping optional et al.

Now I noticed that it does not work with descriptions. Digging into the zod code, I found this:

zod/src/types.ts

Lines 499 to 505 in 0862731

describe(description: string): this {
const This = (this as any).constructor;
return new This({
...this._def,
description,
});
}

My feeling is that this means that the ._def will not point to my schema anymore.
What do you think about adding something like unwrap or innerType to describe, too?
Or am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant