TL;DR
Adding a second middleware to the Inngest client unexpectedly caused TypeScript types to collapse to an empty object. This issue persisted regardless of the middleware's functionality, indicating a deeper problem with type handling.
✦ Why It Matters
Engineers should carefully evaluate middleware interactions in TypeScript to prevent type corruption in their applications.
Key Takeaways
Full Summary
Inngest is a framework that allows developers to run serverless functions with middleware support. A surprising issue arose when two middleware were added to the Inngest client, leading to the TypeScript return type of step.run collapsing to an empty object.
This problem occurred even with no-op middleware, suggesting that the count of middleware was affecting type integrity. The investigation focused on the serialization of results, as Inngest stores the output of each step in JSON format for memoization across retries.
When a function returns a Date, it is serialized as a string, which may disrupt type inference. The findings highlight the importance of understanding how middleware interactions can impact TypeScript types, especially in complex applications.
This issue serves as a reminder for engineers to thoroughly test type behavior when modifying middleware configurations.
Related