Closed
Description
Spec 3.4 says:
Union types are reduced to the smallest possible set of constituent types using these rules
But in compiler they are not reduced in case of inferring type parameters in function invocations. For example:
var o = {};
// According to spec, type of p should be reduced to {}
function f<T>(p: T | typeof o): T
{
var t: T;
var temp = t || o; // here union type is reduced, and it is really {}
return null;
}
// Another function where type of p is really {}. According to spec, it should be equal to f, shouldn't it?
function f2<T>(p: typeof o): T
{
return null;
}
// But really they are different
var e = f(5); // number
var e2 = f2(5); // {}
Could you please clarify, when union type are really reduced and when they are not.