@@ -15171,11 +15171,7 @@ namespace ts {
15171
15171
if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
15172
15172
// Source and target are types originating in the same generic type alias declaration.
15173
15173
// Simply infer from source type arguments to target type arguments.
15174
- const sourceTypes = source.aliasTypeArguments;
15175
- const targetTypes = target.aliasTypeArguments!;
15176
- for (let i = 0; i < sourceTypes.length; i++) {
15177
- inferFromTypes(sourceTypes[i], targetTypes[i]);
15178
- }
15174
+ inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol));
15179
15175
return;
15180
15176
}
15181
15177
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union && !(source.flags & TypeFlags.EnumLiteral && target.flags & TypeFlags.EnumLiteral) ||
@@ -15281,18 +15277,7 @@ namespace ts {
15281
15277
}
15282
15278
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
15283
15279
// If source and target are references to the same generic type, infer from type arguments
15284
- const sourceTypes = (<TypeReference>source).typeArguments || emptyArray;
15285
- const targetTypes = (<TypeReference>target).typeArguments || emptyArray;
15286
- const count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
15287
- const variances = getVariances((<TypeReference>source).target);
15288
- for (let i = 0; i < count; i++) {
15289
- if (i < variances.length && (variances[i] & VarianceFlags.VarianceMask) === VarianceFlags.Contravariant) {
15290
- inferFromContravariantTypes(sourceTypes[i], targetTypes[i]);
15291
- }
15292
- else {
15293
- inferFromTypes(sourceTypes[i], targetTypes[i]);
15294
- }
15295
- }
15280
+ inferFromTypeArguments((<TypeReference>source).typeArguments || emptyArray, (<TypeReference>target).typeArguments || emptyArray, getVariances((<TypeReference>source).target));
15296
15281
}
15297
15282
else if (source.flags & TypeFlags.Index && target.flags & TypeFlags.Index) {
15298
15283
contravariant = !contravariant;
@@ -15412,6 +15397,18 @@ namespace ts {
15412
15397
}
15413
15398
}
15414
15399
15400
+ function inferFromTypeArguments(sourceTypes: readonly Type[], targetTypes: readonly Type[], variances: readonly VarianceFlags[]) {
15401
+ const count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
15402
+ for (let i = 0; i < count; i++) {
15403
+ if (i < variances.length && (variances[i] & VarianceFlags.VarianceMask) === VarianceFlags.Contravariant) {
15404
+ inferFromContravariantTypes(sourceTypes[i], targetTypes[i]);
15405
+ }
15406
+ else {
15407
+ inferFromTypes(sourceTypes[i], targetTypes[i]);
15408
+ }
15409
+ }
15410
+ }
15411
+
15415
15412
function inferFromContravariantTypes(source: Type, target: Type) {
15416
15413
if (strictFunctionTypes || priority & InferencePriority.AlwaysStrict) {
15417
15414
contravariant = !contravariant;
0 commit comments