-
Notifications
You must be signed in to change notification settings - Fork 154
Maintenance: JSONStringified helper does not infer return type #2945
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
@dreamorosi "opened this issue 13 minutes ago" … I basically hit this problem like 15 minutes ago 😅 But yeah, this would definitely be an improvement to have I'm currently working on a personal project with this, but we also use PowerTools and the parser in our company. We have multiple use cases with const MySchema = LambdaFunctionUrlSchema.extend({
headers: MyCustomHeaderSchema,
body: JSONStringified(MyCustomBodySchema),
}); And it'd be super useful to have the correct types in // inside the handler
const body = event.body as z.output<typeof MyCustomBodySchema>; ... but with a team(s) of multiple people developing things, that workaround is easy for someone to forget this workaround and spend time on debugging the incorrect type. |
… and of course another workaround is to use Middy's body JSON parser, then just assume the body is already JSON, and finally using |
Hi @aripalo, I already have a PR up that fixes this. Should be merged on Monday and released mid next week 😊 |
Fantastic! 😍 (… also the timing so I can use this as an excuse to put my coding project on hold until next week and actually enjoy the weekend 😄) |
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.8.0 version! |
Summary
In 2.7.0 we introduced a new helper in the Parser utility, which helps customers to extend built-in Zod schemas that have a stringified body.
The helper, while working at runtime, currently sets the return type of the parsed object to
any
, which defeats the purpose of the DX improvement that the helper was supposed to bring.We should
Why is this needed?
So that customers using the helper can have the correct type on the parsed field.
Which area does this relate to?
Parser
Solution
Follow Zod best practices around writing generic functions.
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: