-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Every non-generic function can be expressed as generic function with a single type parameter corresponding to each argument. Explicit parameter type annotations simply correspond to extends
constraints on the type parameters of the generic equivalent.
While the title of the issue is "eliminate non-generic functions", in practice this simply gets rid of all the syntax ceremony involved in declaring generic functions. A function declaration as follows:
function repeat(item, n: number) => Array(n).fill(item)
will be inferred as: type F = <T1 extends any, T2 extends number>(item: T1, number: T2) => T1[]
, and the result of invoking it with repeat("foo", 10)
is inferred as string[]
, not any[]
.
KaelWD and outerlook
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript