|
| 1 | + |
| 2 | + |
| 3 | + |
1 | 4 | /* @internal */
|
2 | 5 | namespace ts {
|
3 | 6 | const ambientModuleSymbolRegex = /^".+"$/;
|
@@ -13460,6 +13463,7 @@ namespace ts {
|
13460 | 13463 | let symbolStack: Symbol[];
|
13461 | 13464 | let visited: Map<boolean>;
|
13462 | 13465 | let contravariant = false;
|
| 13466 | + let bivariant = false; |
13463 | 13467 | let propagationType: Type;
|
13464 | 13468 | let allowComplexConstraintInference = true;
|
13465 | 13469 | inferFromTypes(originalSource, originalTarget);
|
@@ -13546,7 +13550,9 @@ namespace ts {
|
13546 | 13550 | }
|
13547 | 13551 | if (priority === inference.priority) {
|
13548 | 13552 | const candidate = propagationType || source;
|
13549 |
| - if (contravariant) { |
| 13553 | + // We make contravariant inferences only if we are in a pure contravariant position, |
| 13554 | + // i.e. only if we have not descended into a bivariant position. |
| 13555 | + if (contravariant && !bivariant) { |
13550 | 13556 | inference.contraCandidates = append(inference.contraCandidates, candidate);
|
13551 | 13557 | }
|
13552 | 13558 | else {
|
@@ -13798,7 +13804,12 @@ namespace ts {
|
13798 | 13804 |
|
13799 | 13805 | function inferFromSignature(source: Signature, target: Signature, skipParameters: boolean) {
|
13800 | 13806 | if (!skipParameters) {
|
| 13807 | + const saveBivariant = bivariant; |
| 13808 | + const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown; |
| 13809 | + // Once we descend into a bivariant signature we remain bivariant for all nested inferences |
| 13810 | + bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor; |
13801 | 13811 | forEachMatchingParameterType(source, target, inferFromContravariantTypes);
|
| 13812 | + bivariant = saveBivariant; |
13802 | 13813 | }
|
13803 | 13814 | const sourceTypePredicate = getTypePredicateOfSignature(source);
|
13804 | 13815 | const targetTypePredicate = getTypePredicateOfSignature(target);
|
|
0 commit comments