From 8ffc42f5a6739f257ecf52a24fee0c45c1c282a3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 3 Sep 2019 15:24:49 -0700 Subject: [PATCH] Don't instantiate-in-context-of when inferring to type variable --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfad47b6533..f51aee47a1a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -177,6 +177,7 @@ namespace ts { const enum ContextFlags { None = 0, Signature = 1 << 0, // Obtaining contextual signature + NoConstraints = 1 << 1, // Don't obtain type variable constraints } const enum AccessFlags { @@ -19193,7 +19194,7 @@ namespace ts { getContextualTypeForObjectLiteralMethod(node, contextFlags) : getContextualType(node, contextFlags); const instantiatedType = instantiateContextualType(contextualType, node, contextFlags); - if (instantiatedType) { + if (instantiatedType && !(contextFlags && contextFlags & ContextFlags.NoConstraints && instantiatedType.flags & TypeFlags.TypeVariable)) { const apparentType = mapType(instantiatedType, getApparentType, /*noReductions*/ true); if (apparentType.flags & TypeFlags.Union) { if (isObjectLiteralExpression(node)) { @@ -25098,8 +25099,8 @@ namespace ts { const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true); const signature = callSignature || constructSignature; if (signature && signature.typeParameters) { - const contextualType = getApparentTypeOfContextualType(node); - if (contextualType && !isMixinConstructorType(contextualType)) { + const contextualType = getApparentTypeOfContextualType(node, ContextFlags.NoConstraints); + if (contextualType) { const contextualSignature = getSingleSignature(getNonNullableType(contextualType), callSignature ? SignatureKind.Call : SignatureKind.Construct, /*allowMembers*/ false); if (contextualSignature && !contextualSignature.typeParameters) { if (checkMode & CheckMode.SkipGenericFunctions) {