Hello, I'm trying to recreate a middleware implementation similar to middy.js (more for my own understanding than anything), but I'm struggling with how to correctly type the middleware factory.
Here's a Playground link for the implementation of the factory and a desired outcome.
I think for the end handler to receive a correctly typed event, I need to supply a return type to/for the use calls and use that to modify types within the factory/handler. The problem here is that I have no idea how to achieve this, or even where to begin looking.
Is there a known pattern/name for what I'm trying to achieve? Would anyone have any pointers on how to approach this? TIA for any help.
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.