Open
Description
Search Terms
unification generic inference
Suggestion
Today, TypeScript cannot retain or synthesize free type parameters during generic inference. This means code like this doesn't typecheck, when it should:
function identity<T>(arg: T) { return arg; }
function memoize<F extends (...args: unknown[]) => unknown>(fn: F): F { return fn; }
// memid: unknown => unknown
// desired: memid<T>(T) => T
const memid = memoize(identity);
Use Cases
Many functional programming patterns would greatly benefit from this.
The purpose of this issue is to gather use cases and examine the cost/benefit of using a different inference algorithm.
Examples
Haven't extensively researched these to validate that they require unification, but it's a start:
#9366
#3423
#25092
#26951 (design meeting notes with good examples)
#25826
#10247