From 6b1c84e84a51031034d7db12f35f809a054abe32 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 29 May 2018 17:55:31 -0700 Subject: [PATCH] Remove eager resolution of distributive conditional types --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f562bd62998..712eb182e91 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8969,9 +8969,6 @@ namespace ts { if (checkType === wildcardType || extendsType === wildcardType) { return wildcardType; } - if (extendsType.flags & TypeFlags.AnyOrUnknown) { - return instantiateType(root.trueType, mapper); - } // If this is a distributive conditional type and the check type is generic we need to defer // resolution of the conditional type such that a later instantiation will properly distribute // over union types. @@ -8988,6 +8985,9 @@ namespace ts { combinedMapper = combineTypeMappers(mapper, context); } if (!isDeferred) { + if (extendsType.flags & TypeFlags.AnyOrUnknown) { + return instantiateType(root.trueType, mapper); + } // Return union of trueType and falseType for 'any' since it matches anything if (checkType.flags & TypeFlags.Any) { return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);