From abc61a0949bbd03684cbd6d5b06b20a31216578c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 15 Aug 2019 18:08:01 -0700 Subject: [PATCH] Add InferencePriority.Circularity per CR feedback --- src/compiler/checker.ts | 6 +++--- src/compiler/types.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a61d3aa177..b15e4d6afb9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15696,7 +15696,7 @@ namespace ts { inferencePriority = Math.min(inferencePriority, status); return; } - (visited || (visited = createMap())).set(key, -1); + (visited || (visited = createMap())).set(key, InferencePriority.Circularity); const saveInferencePriority = inferencePriority; inferencePriority = InferencePriority.MaxValue; action(source, target); @@ -15789,7 +15789,7 @@ namespace ts { inferencePriority = InferencePriority.MaxValue; inferFromTypes(sources[i], t); if (inferencePriority === priority) matched[i] = true; - inferenceCircularity = inferenceCircularity || inferencePriority < 0; + inferenceCircularity = inferenceCircularity || inferencePriority === InferencePriority.Circularity; inferencePriority = Math.min(inferencePriority, saveInferencePriority); } } @@ -15901,7 +15901,7 @@ namespace ts { const symbol = isNonConstructorObject ? target.symbol : undefined; if (symbol) { if (contains(symbolStack, symbol)) { - inferencePriority = -1; + inferencePriority = InferencePriority.Circularity; return; } (symbolStack || (symbolStack = [])).push(symbol); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7d98b7761ac..1d8a6f3eb7f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4474,6 +4474,7 @@ namespace ts { MaxValue = 1 << 8, // Seed for inference priority tracking PriorityImpliesCombination = ReturnType | MappedTypeConstraint | LiteralKeyof, // These priorities imply that the resulting type should be a combination of all candidates + Circularity = -1, // Inference circularity (value less than all other priorities) } /* @internal */