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 #3833

Open
hco opened this issue Nov 4, 2024 · 1 comment
Open

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

hco opened this issue Nov 4, 2024 · 1 comment

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?

@m10rten
Copy link
Contributor

m10rten commented Nov 8, 2024

Hi, this pattern is very common in zod, the general def type name will be available, might not be what you need but that could be a pointer in the right direction.

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

2 participants