@@ -11490,20 +11490,21 @@ namespace ts {
11490
11490
let symbolStack: Symbol[];
11491
11491
let visited: Map<boolean>;
11492
11492
let contravariant = false;
11493
+ let propagationType: Type;
11493
11494
inferFromTypes(originalSource, originalTarget);
11494
11495
11495
11496
function inferFromTypes(source: Type, target: Type) {
11496
11497
if (!couldContainTypeVariables(target)) {
11497
11498
return;
11498
11499
}
11499
- if (source === neverType || source === wildcardType ) {
11500
- // We are inferring from 'never ' or the wildcard type . We want to infer this
11501
- // type for every type parameter referenced in the target type, so we infer from
11502
- // target to itself with a flag we check when recording candidates .
11503
- const savePriority = priority ;
11504
- priority | = source === neverType ? InferencePriority.Never : InferencePriority.Wildcard ;
11500
+ if (source.flags & (TypeFlags.Any | TypeFlags.Never) && source !== silentNeverType ) {
11501
+ // We are inferring from 'any ' or 'never' . We want to infer this type for every type parameter
11502
+ // referenced in the target type, so we record the propagation type and infer from the target
11503
+ // to itself. Then, as we find candidates we substitute the propagation type .
11504
+ const savePropagationType = propagationType ;
11505
+ propagationType = source;
11505
11506
inferFromTypes(target, target);
11506
- priority = savePriority ;
11507
+ propagationType = savePropagationType ;
11507
11508
return;
11508
11509
}
11509
11510
if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
@@ -11567,16 +11568,13 @@ namespace ts {
11567
11568
const inference = getInferenceInfoForType(target);
11568
11569
if (inference) {
11569
11570
if (!inference.isFixed) {
11570
- const p = priority & InferencePriority.Mask;
11571
- if (inference.priority === undefined || p < inference.priority) {
11571
+ if (inference.priority === undefined || priority < inference.priority) {
11572
11572
inference.candidates = undefined;
11573
11573
inference.contraCandidates = undefined;
11574
- inference.priority = p ;
11574
+ inference.priority = priority ;
11575
11575
}
11576
- if (p === inference.priority) {
11577
- const candidate = priority & InferencePriority.Never ? neverType :
11578
- priority & InferencePriority.Wildcard ? wildcardType :
11579
- source;
11576
+ if (priority === inference.priority) {
11577
+ const candidate = propagationType || source;
11580
11578
if (contravariant) {
11581
11579
inference.contraCandidates = append(inference.contraCandidates, candidate);
11582
11580
}
0 commit comments