From c9a3ea6fe0fdbcb1dfe2d413c136feaf9cb774fb Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 11 May 2016 12:49:42 -0700 Subject: [PATCH] Stop analyzing loop branches when declared type is seen --- src/compiler/checker.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 85e78324cc7..fa8004a5d91 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7780,16 +7780,15 @@ namespace ts { if (cache[key]) { return cache[key]; } - // If the type at a particular antecedent path is the declared type and the - // reference is known to always be assigned (i.e. when declared and initial types - // are the same), there is no reason to process more antecedents since the only - // possible outcome is subtypes that will be removed in the final union type anyway. - if (type === declaredType && declaredType === initialType) { - return cache[key] = type; - } if (!contains(antecedentTypes, type)) { antecedentTypes.push(type); } + // If the type at a particular antecedent path is the declared type there is no + // reason to process more antecedents since the only possible outcome is subtypes + // that will be removed in the final union type anyway. + if (type === declaredType) { + break; + } } return cache[key] = getUnionType(antecedentTypes); }