TypeScript Infers Only the Last Overload — Here's How Intersection Order Changes That
A developer building a lambda-based translation key selector with i18next ran into a TypeScript limitation: when inferring from an overloaded function type, TypeScript only resolves the last call signature. Standard workarounds found online relied on hardcoded overload tables supporting a fixed number of signatures, which the developer found unsatisfactory. Experimenting with intersection types, they discovered that the order of operands in an intersection affects which overload TypeScript surfaces during inference. Placing a known call signature on the left side of the intersection — before the overloaded type — caused TypeScript to treat that signature as the last one for inference purposes. This intersection-order trick offered a more flexible path toward extracting and transforming all overloads from a function type without hardcoding limits.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in