Closed
Description
When a generic type is used in an intersection type passed to a function, TS fails to infer that generic type.
Example:
interface Man {
walks: boolean;
}
interface Bear {
roars: boolean;
}
interface Pig {
oinks: boolean;
}
declare function pigify<T>(y: T & Bear): T & Pig;
declare var mbp: Man & Bear;
pigify(mbp).oinks; // OK, mbp is treated as Pig
pigify(mbp).walks; // ERROR, mbp not recognized as Man
This seems like the inverse of #2211. Unlike union types however, the use of an intersection type in the param should provide enough information to make the required inference.
That is, if I pass a value of type Man & Bear
to a function expecting T & Bear
, then T
should either be Man
or Man & Bear
, either of which would be enough to infer that T has all of the properties expected of Man
. Instead, TS seems to be inferring T
to be of type {}
.
Am I missing something here?