-
Notifications
You must be signed in to change notification settings - Fork 153
Feature request: infer ParsedResult
types from inputs of parse function
#3096
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
Comments
I also noticed that the API docs of the feature are incorrect and don't mention the fact that you need two types. I have started a branch to fix this, if we decide to fix this we can continue working on it. |
@am29d - note that I might have been far off with this suggestion and this is simply how Zod types work. Before moving onto an implementation I'd like us to discuss options if that's ok with you - I'd want to avoid us touching dozen files just to later throw it away. Also, nobody seem to have engaged with this issue - so perhaps we could also just close it and revisit this if there's ever demand. |
As discussed during today's meeting @am29d has been looking into this and the change will require updating the type of the He's going to do a small PoC to see if it's worth changing, but if too big we'll just drop the request and close the issue as not planned by the end of the iteration. |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.14.0 version! |
Use case
When using the Parser with the
safeParse
option enabled, the result is aParsedResult
type that can contain either the parsed payload or an error depending on the result of the parsing.Today, customers need to specify two types: one for the input type, usually the one of the envelope, and an output type, either the schema or the transformed type.
This is ok when using envelopes, but when parsing a schema directly the two types can be redundant and/or confusing.
I don't know if it's possible, but we could explore the possibility of making the second type optional when typing the
ParsedResult
or even making it optional and infer the types from the decorator usage.Solution/User Experience
Before
After
Especially in cases where we don't use an envelope, the
Output
type is always thez.infer<typeof XXXSchema>
.Alternative solutions
So that one can just specify the first one when not using envelopes.
This solution however might be counterintuitive because we are now reverting the order of the parameters. The good thing about the current solution is that logically input comes before the output.
The text was updated successfully, but these errors were encountered: