Open
Description
openedon Jul 26, 2017
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[]
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment