Closed
Description
TypeScript Version: 2.0.6
Code
interface GenericIdentityFn {
<T>(arg: T): T;
}
function identity(n: number): string {
return n.toString();
}
let myIdentity: GenericIdentityFn = identity;
Expected behavior:
The code should not compile because identity
does not satisfy the constraints of GenericIdentityFn
. Namely, it accepts an argument of type number
and returns type string
, whereas the interface GenericIdentityFn
describes a function that accepts an argument of type T
and returns type T
.
Actual behavior:
The code compiles.
Other notes:
This is based on an example from https://www.typescriptlang.org/docs/handbook/generics.html.