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