@@ -9843,9 +9843,8 @@ namespace ts {
9843
9843
if (flags & TypeFlags.NonPrimitive) {
9844
9844
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
9845
9845
}
9846
- if (flags & TypeFlags.TypeParameter) {
9847
- const constraint = getConstraintOfTypeParameter(<TypeParameter>type);
9848
- return getTypeFacts(constraint || emptyObjectType);
9846
+ if (flags & TypeFlags.TypeVariable) {
9847
+ return getTypeFacts(getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType);
9849
9848
}
9850
9849
if (flags & TypeFlags.UnionOrIntersection) {
9851
9850
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
@@ -10632,8 +10631,16 @@ namespace ts {
10632
10631
// is a supertype of that primitive type. For example, type 'any' can be narrowed
10633
10632
// to one of the primitive types.
10634
10633
const targetType = typeofTypesByName.get(literal.text);
10635
- if (targetType && isTypeSubtypeOf(targetType, type)) {
10636
- return targetType;
10634
+ if (targetType) {
10635
+ if (isTypeSubtypeOf(targetType, type)) {
10636
+ return targetType;
10637
+ }
10638
+ if (type.flags & TypeFlags.TypeVariable) {
10639
+ const constraint = getBaseConstraintOfType(<TypeVariable>type) || anyType;
10640
+ if (isTypeSubtypeOf(targetType, constraint)) {
10641
+ return getIntersectionType([type, targetType]);
10642
+ }
10643
+ }
10637
10644
}
10638
10645
}
10639
10646
const facts = assumeTrue ?
@@ -10731,10 +10738,9 @@ namespace ts {
10731
10738
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
10732
10739
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
10733
10740
// two types.
10734
- const targetType = type.flags & TypeFlags.TypeParameter ? getApparentType(type) : type;
10735
10741
return isTypeSubtypeOf(candidate, type) ? candidate :
10736
10742
isTypeAssignableTo(type, candidate) ? type :
10737
- isTypeAssignableTo(candidate, targetType ) ? candidate :
10743
+ isTypeAssignableTo(candidate, type ) ? candidate :
10738
10744
getIntersectionType([type, candidate]);
10739
10745
}
10740
10746
0 commit comments