Sneruz
Reducing Redundant API Handlers While Preserving TypeScript Types
I have multiple handlers that are nearly identical except for the types they use and the endpoint paths. Here's a simplified example:
As you can see, the event handlers for A, B, and C are very similar, with only the types and endpoint paths being different.
What I've Tried:
I attempted to reduce redundancy by using dynamic route parameters:
While this simplifies the code, I'm losing the specific TypeScript types for each request and response.
My Question:
Is there a way to eliminate the redundancy in my API handlers while maintaining specific TypeScript types for each endpoint?
5 replies