@@ -8805,8 +8805,7 @@ namespace ts {
8805
8805
return true;
8806
8806
}
8807
8807
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
8808
- const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
8809
- const related = relation.get(id);
8808
+ const related = relation.get(getRelationKey(source, target, relation));
8810
8809
if (related !== undefined) {
8811
8810
return related === RelationComparisonResult.Succeeded;
8812
8811
}
@@ -9207,7 +9206,7 @@ namespace ts {
9207
9206
if (overflow) {
9208
9207
return Ternary.False;
9209
9208
}
9210
- const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id ;
9209
+ const id = getRelationKey( source, target, relation) ;
9211
9210
const related = relation.get(id);
9212
9211
if (related !== undefined) {
9213
9212
if (reportErrors && related === RelationComparisonResult.Failed) {
@@ -9772,6 +9771,45 @@ namespace ts {
9772
9771
}
9773
9772
}
9774
9773
9774
+ function isUnconstrainedTypeParameter(type: Type) {
9775
+ return type.flags & TypeFlags.TypeParameter && !getConstraintFromTypeParameter(<TypeParameter>type);
9776
+ }
9777
+
9778
+ function isTypeReferenceWithGenericArguments(type: Type) {
9779
+ return getObjectFlags(type) & ObjectFlags.Reference && some((<TypeReference>type).typeArguments, isUnconstrainedTypeParameter);
9780
+ }
9781
+
9782
+ function getTypeReferenceId(type: TypeReference, typeParameters: Type[]) {
9783
+ let result = "" + type.id;
9784
+ for (const t of type.typeArguments) {
9785
+ if (isUnconstrainedTypeParameter(t)) {
9786
+ let index = indexOf(typeParameters, t);
9787
+ if (index < 0) {
9788
+ index = typeParameters.length;
9789
+ typeParameters.push(t);
9790
+ }
9791
+ result += "=" + index;
9792
+ }
9793
+ else {
9794
+ result += "-" + t.id;
9795
+ }
9796
+ }
9797
+ return result;
9798
+ }
9799
+
9800
+ function getRelationKey(source: Type, target: Type, relation: Map<RelationComparisonResult>) {
9801
+ if (relation === identityRelation && source.id > target.id) {
9802
+ const temp = source;
9803
+ source = target;
9804
+ target = temp;
9805
+ }
9806
+ if (isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target)) {
9807
+ const typeParameters: Type[] = [];
9808
+ return getTypeReferenceId(<TypeReference>source, typeParameters) + "," + getTypeReferenceId(<TypeReference>target, typeParameters);
9809
+ }
9810
+ return source.id + "," + target.id;
9811
+ }
9812
+
9775
9813
// Invoke the callback for each underlying property symbol of the given symbol and return the first
9776
9814
// value that isn't undefined.
9777
9815
function forEachProperty<T>(prop: Symbol, callback: (p: Symbol) => T): T {
0 commit comments