Closed
Description
When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how identityM
has the generic type parameter A
changed into {}
, resulting in a loss of type safety in the rest of the code.
Ideally identityM
would have the type <A>(a: A) => A
. If this isn't possible, issuing a compiler warning (or error) about loss of genericity would be very helpful in tracking down errors like this.
function mirror<A, B>(f: (a: A) => B): (a: A) => B { return f; }
function identity<A>(a: A): A { return a; }
var identityM = mirror(identity); // type: (a: {}) => {}
var x = 1;
var y = identity(x); // type: number
var z = identityM(x); // type: {}