Feature request: infer ParsedResult
types from inputs of parse function
#3096
Labels
confirmed
The scope is clear, ready for implementation
feature-request
This item refers to a feature request for an existing or new utility
parser
This item relates to the Parser Utility
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: