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

Add a way for .superRefine() to narrow down the output type #1602

Closed
DanielBreiner opened this issue Nov 25, 2022 · 3 comments · Fixed by #1615
Closed

Add a way for .superRefine() to narrow down the output type #1602

DanielBreiner opened this issue Nov 25, 2022 · 3 comments · Fixed by #1615

Comments

@DanielBreiner
Copy link

Currently, refine has a type guard which is used to narrow down the output type.

refine<RefinedOutput extends Output>(
  check: (arg: Output) => arg is RefinedOutput,
  message?: /* ... */
): ZodEffects<this, RefinedOutput, RefinedOutput>;

superRefine: (
  refinement: RefinementEffect<Output>["refinement"]
) => ZodEffects<this, Output, Input>;

I propose adding this functionality to superRefine as well.

@maxArturo
Copy link
Contributor

@DanielBreiner Agreed on this front. This is a fun little exercise in TS wrangling that I'm enjoying... :D

@maxArturo
Copy link
Contributor

@DanielBreiner do you mind looking at #1615 and seeing if it works for you?

@DanielBreiner
Copy link
Author

@maxArturo Looks great, thanks a lot for the PR.

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

Successfully merging a pull request may close this issue.

2 participants