Feature request: allow parser set event type of handler with middy
Use case
middy can pass event type like as this. So we can pass inferred event type from zod schema to handler.
Solution/User Experience
const detailSchema = z.object({
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
message: z.string(),
});
export const handler = middy()
// when using parser
.use(parser({ schema: detailSchema, envelope: EventBridgeEnvelope }))
// handler will get event type already inferred without type annotation.
.handler(async (event) => {
logger.inf(event.detail.message)
});
Alternative solutions
No response
Acknowledgment
- [X] This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- [X] Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Hey @yamatatsu, thanks for raising the issue.
~~In your example, I think you missed the types in the middy() call. Can you modify the solution code block to reflect that? In the meantime, I will investigate how we could add event types to middy call.~~
Edit: now that Andrea pointed out to me, I got your point more clearly. You want to infer the type in the handler if it comes after the parser. I'd need to investigate a bit more what it will take to implement it.
⚠️ COMMENT VISIBILITY WARNING ⚠️
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.6.0 version!