-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Meta-IssueAn issue about the team, or the direction of TypeScriptAn issue about the team, or the direction of TypeScript
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
alexrock, rkirov, dragomirtitian, jscheiny, yortus and 89 moredragomirtitian, Nathan-Fenner, raveclassic, rifler, Bnaya and 11 morefvilante, Bnaya, VitorLuizC, motss, JoseCrz and 7 more3nprob, janekeilts and davidmyersdev
Metadata
Metadata
Assignees
Labels
Meta-IssueAn issue about the team, or the direction of TypeScriptAn issue about the team, or the direction of TypeScript