You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function identity<T>(arg: T): T {
return arg;
}
var myIdentity: <T>(arg: T) => string = identity;
var a = myIdentity<string>("string")
var b = myIdentity<number>(100)
outputs the following javascript:
function identity(arg) {
return arg;
}
var myIdentity = identity;
var a = myIdentity("string");
var b = myIdentity(100);
I put the type signature of the variable myIdentity as <T>(arg: T) => string
where the return type is string instead of T (that I expect to be correct).
I expected the Typescript compiler to show an error because the return types
don't match. However, the code compiled without any error.
Specs:
Mac OS X 10.11
tsc --version outputs: message TS6029: Version 1.6.2