-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for 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 91 moredragomirtitian, Nathan-Fenner, raveclassic, rifler, Bnaya and 11 morefvilante, Bnaya, VitorLuizC, motss, JoseCrz and 7 more3nprob, janekeilts and davidmyersdev
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript