@@ -5253,7 +5253,7 @@ namespace ts {
52535253 for (let i = 0; i < checkCount; i++) {
52545254 const s = i < sourceMax ? getTypeOfSymbol(sourceParams[i]) : getRestTypeOfSignature(source);
52555255 const t = i < targetMax ? getTypeOfSymbol(targetParams[i]) : getRestTypeOfSignature(target);
5256- const related = compareTypes(t, s , /*reportErrors*/ false) || compareTypes(s, t , reportErrors);
5256+ const related = compareTypes(s, t , /*reportErrors*/ false) || compareTypes(t, s , reportErrors);
52575257 if (!related) {
52585258 if (reportErrors) {
52595259 errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
@@ -6455,8 +6455,10 @@ namespace ts {
64556455 function inferTypes(context: InferenceContext, source: Type, target: Type) {
64566456 let sourceStack: Type[];
64576457 let targetStack: Type[];
6458+ const maxDepth = 5;
64586459 let depth = 0;
64596460 let inferiority = 0;
6461+ const visited: Map<boolean> = {};
64606462 inferFromTypes(source, target);
64616463
64626464 function isInProcess(source: Type, target: Type) {
@@ -6582,10 +6584,21 @@ namespace ts {
65826584 if (isInProcess(source, target)) {
65836585 return;
65846586 }
6587+ // we delibirately limit the depth we examine to infer types: this speeds up the overall inference process
6588+ // and user rarely expects inferences to be made from the deeply nested constituents.
6589+ if (depth > maxDepth) {
6590+ return;
6591+ }
65856592 if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
65866593 return;
65876594 }
65886595
6596+ const key = source.id + "," + target.id;
6597+ if (hasProperty(visited, key)) {
6598+ return;
6599+ }
6600+ visited[key] = true;
6601+
65896602 if (depth === 0) {
65906603 sourceStack = [];
65916604 targetStack = [];
0 commit comments