From 23473e021b0006f37d0d2e8f9c5c9de182641cd6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Feb 2019 17:14:00 -0800 Subject: [PATCH] Skip generic functions along with context sensitive arguments --- src/compiler/checker.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 440dacc7597..e4fbbd6a9a6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -685,6 +685,7 @@ namespace ts { Contextual = 1 << 0, // Explicitly assigned contextual type, therefore not cacheable Inferential = 1 << 1, // Inferential typing SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions + SkipGenericFunctions = 1 << 3, // Skip single signature generic functions } const enum CallbackCheck { @@ -20053,7 +20054,8 @@ namespace ts { const paramType = getTypeAtPosition(signature, i); // For context sensitive arguments we pass the identityMapper, which is a signal to treat all // context sensitive function expressions as wildcards - const checkMode = excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0; + const checkMode = (excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) | + (excludeArgument ? CheckMode.SkipGenericFunctions : 0); const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode); inferTypes(context.inferences, argType, paramType); } @@ -20190,7 +20192,8 @@ namespace ts { const arg = args[i]; if (arg.kind !== SyntaxKind.OmittedExpression) { const paramType = getTypeAtPosition(signature, i); - const checkMode = excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0; + const checkMode = (excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) | + (excludeArgument ? CheckMode.SkipGenericFunctions : 0); const argType = checkExpressionWithContextualType(arg, paramType, undefined, checkMode); // If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter), // we obtain the regular type of any object literal arguments because we may not have inferred complete @@ -23266,9 +23269,12 @@ namespace ts { } function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration | QualifiedName, type: Type, checkMode?: CheckMode) { - if (checkMode && checkMode & CheckMode.Inferential) { + if (checkMode && checkMode & (CheckMode.Inferential | CheckMode.SkipGenericFunctions)) { const signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { + if (checkMode & CheckMode.SkipGenericFunctions) { + return anyFunctionType; + } const contextualType = getApparentTypeOfContextualType(node); if (contextualType) { const contextualSignature = getSingleCallSignature(getNonNullableType(contextualType)); @@ -23278,7 +23284,6 @@ namespace ts { } } } - return type; }