-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 types to extract error results from schema #856
Conversation
[P in keyof TypeOf<T>]?: U[]; | ||
}; | ||
}; | ||
export type TypeOfFormErrors< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a single z.inferFormErrors
type that just has the signature of z.inferFlattenedError
, but I wanted to avoid confusion between results of flatten()
vs formErrors
getter.
What would you prefer? A single type, or is the convince alias type useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally appreciate the alias here since it actually gives a pretty nice hint at what is actually happening.
This would be quite helpful! I would like to use this in the example project for integrating Remix with zod. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any type-level tests that we can add, maybe some AssertEqual
to the errors test suite?
[P in keyof TypeOf<T>]?: U[]; | ||
}; | ||
}; | ||
export type TypeOfFormErrors< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally appreciate the alias here since it actually gives a pretty nice hint at what is actually happening.
I was thinking the same. There's a few libraries to do so; dtslint and tsd are the two most prominent. The latter has some differences with dtslint. |
I just meant literally using the existing |
Oh, sorry I totally misunderstood. I'll add some tests for this :) |
@scotttrinh I added tests for type inference and type assertion with I don't know if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great tests, great implementation, thanks for your contribution!
Wonderful! Thank you! |
When can we expect a release of this? |
z.inferFlattenedErrors
and alias typez.inferFormErrors
to infer error result types forflatten()
from a schema.flatten
to support type-safety with the new types.Fixes #855