Adding a second middleware broke our typescript types
Blog post from Inngest
In this detailed blog post, Linell Bonnette explores a complex issue encountered in TypeScript when using multiple middleware with the Inngest client, which causes the TypeScript types to break. The author discovers that when two middleware are applied, the return type of step.run unexpectedly collapses to an empty object due to the serialization and transformation process involving Jsonify, which composes multiple times when middleware is stacked. This issue arises from an optional property that introduces an undefined key in TypeScript’s mapped types, leading to an ill-formed type that the compiler silently accepts. Despite previous community attempts to resolve the problem, the author identifies that the root cause lies in where undefined enters the union of keys and proposes a fix by excluding undefined from the union, which effectively prevents type corruption. Further refinement is suggested by employing key remapping with 'as' to eliminate the need for additional exclusion steps, ensuring a more robust and simplified solution. This nuanced investigation highlights the subtleties of TypeScript's type system and the importance of testing type compositions thoroughly.
No tracked trend matches for this post yet.
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.