From b44bfaaaa8edf88e83779e1f0399a8518dfff389 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Feb 2019 06:15:26 -0800 Subject: [PATCH 1/6] Convert CheckMode to a flags style enum --- src/compiler/checker.ts | 43 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 002fdecc0cd39..440dacc759733 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -681,10 +681,10 @@ namespace ts { } const enum CheckMode { - Normal = 0, // Normal type checking - SkipContextSensitive = 1, // Skip context sensitive function expressions - Inferential = 2, // Inferential typing - Contextual = 3, // Normal type checking informed by a contextual type, therefore not cacheable + Normal = 0, // Normal type checking + Contextual = 1 << 0, // Explicitly assigned contextual type, therefore not cacheable + Inferential = 1 << 1, // Inferential typing + SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions } const enum CallbackCheck { @@ -19985,10 +19985,9 @@ namespace ts { function inferJsxTypeArguments(node: JsxOpeningLikeElement, signature: Signature, excludeArgument: ReadonlyArray | undefined, context: InferenceContext): Type[] { const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node); - - const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, excludeArgument && excludeArgument[0] !== undefined ? identityMapper : context); + const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0; + const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode); inferTypes(context.inferences, checkAttrType, paramType); - return getInferredTypes(context); } @@ -20054,8 +20053,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 mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : context; - const argType = checkExpressionWithContextualType(arg, paramType, mapper); + const checkMode = excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0; + const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode); inferTypes(context.inferences, argType, paramType); } } @@ -20083,7 +20082,7 @@ namespace ts { // and the argument are ...x forms. return arg.kind === SyntaxKind.SyntheticExpression ? createArrayType((arg).type) : - getArrayifiedType(checkExpressionWithContextualType((arg).expression, restType, context)); + getArrayifiedType(checkExpressionWithContextualType((arg).expression, restType, context, CheckMode.Normal)); } } const contextualType = getIndexTypeOfType(restType, IndexKind.Number) || anyType; @@ -20091,7 +20090,7 @@ namespace ts { const types = []; let spreadIndex = -1; for (let i = index; i < argCount; i++) { - const argType = checkExpressionWithContextualType(args[i], contextualType, context); + const argType = checkExpressionWithContextualType(args[i], contextualType, context, CheckMode.Normal); if (spreadIndex < 0 && isSpreadArgument(args[i])) { spreadIndex = i - index; } @@ -20156,7 +20155,8 @@ namespace ts { // However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props, // can be specified by users through attributes property. const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node); - const attributesType = checkExpressionWithContextualType(node.attributes, paramType, excludeArgument && excludeArgument[0] ? identityMapper : undefined); + const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0; + const attributesType = checkExpressionWithContextualType(node.attributes, paramType, undefined, checkMode); return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes); } @@ -20190,7 +20190,8 @@ namespace ts { const arg = args[i]; if (arg.kind !== SyntaxKind.OmittedExpression) { const paramType = getTypeAtPosition(signature, i); - const argType = checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + const checkMode = excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 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 // parameter types yet and therefore excess property checks may yield false positives (see #17041). @@ -21145,7 +21146,7 @@ namespace ts { if (isJsxIntrinsicIdentifier(node.tagName)) { const result = getIntrinsicAttributesTypeFromJsxOpeningLikeElement(node); const fakeSignature = createSignatureForJSXIntrinsic(node, result); - checkTypeAssignableToAndOptionallyElaborate(checkExpressionWithContextualType(node.attributes, getEffectiveFirstArgumentForJsxSignature(fakeSignature, node), /*mapper*/ undefined), result, node.tagName, node.attributes); + checkTypeAssignableToAndOptionallyElaborate(checkExpressionWithContextualType(node.attributes, getEffectiveFirstArgumentForJsxSignature(fakeSignature, node), /*mapper*/ undefined, CheckMode.Normal), result, node.tagName, node.attributes); return fakeSignature; } const exprTypes = checkExpression(node.tagName); @@ -22086,7 +22087,7 @@ namespace ts { checkNodeDeferred(node); // The identityMapper object is used to indicate that function expressions are wildcards - if (checkMode === CheckMode.SkipContextSensitive && isContextSensitive(node)) { + if (checkMode && checkMode & CheckMode.SkipContextSensitive && isContextSensitive(node)) { // Skip parameters, return signature with return type that retains noncontextual parts so inferences can still be drawn in an early stage if (!getEffectiveReturnTypeNode(node) && hasContextSensitiveReturnExpression(node)) { const links = getNodeLinks(node); @@ -22126,7 +22127,7 @@ namespace ts { const signature = getSignaturesOfType(type, SignatureKind.Call)[0]; if (isContextSensitive(node)) { const contextualMapper = getContextualMapper(node); - if (checkMode === CheckMode.Inferential) { + if (checkMode && checkMode & CheckMode.Inferential) { inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper); } const instantiatedContextualSignature = contextualMapper === identityMapper ? @@ -23137,15 +23138,13 @@ namespace ts { return node; } - function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper: TypeMapper | undefined): Type { + function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper: TypeMapper | undefined, checkMode: CheckMode): Type { const context = getContextNode(node); const saveContextualType = context.contextualType; const saveContextualMapper = context.contextualMapper; context.contextualType = contextualType; context.contextualMapper = contextualMapper; - const checkMode = contextualMapper === identityMapper ? CheckMode.SkipContextSensitive : - contextualMapper ? CheckMode.Inferential : CheckMode.Contextual; - const type = checkExpression(node, checkMode); + const type = checkExpression(node, checkMode | CheckMode.Contextual | (contextualMapper ? CheckMode.Inferential : 0)); // We strip literal freshness when an appropriate contextual type is present such that contextually typed // literals always preserve their literal types (otherwise they might widen during type inference). An alternative // here would be to not mark contextually typed literals as fresh in the first place. @@ -23159,7 +23158,7 @@ namespace ts { function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - if (checkMode) { + if (checkMode && checkMode !== CheckMode.Normal) { return checkExpression(node, checkMode); } // When computing a type that we're going to cache, we need to ignore any ongoing control flow @@ -23267,7 +23266,7 @@ namespace ts { } function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration | QualifiedName, type: Type, checkMode?: CheckMode) { - if (checkMode === CheckMode.Inferential) { + if (checkMode && checkMode & CheckMode.Inferential) { const signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { const contextualType = getApparentTypeOfContextualType(node); From 23473e021b0006f37d0d2e8f9c5c9de182641cd6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Feb 2019 17:14:00 -0800 Subject: [PATCH 2/6] 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 440dacc759733..e4fbbd6a9a654 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; } From 35ebbece49320b48df5a0cb048a08a34256718e0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 1 Mar 2019 09:12:24 -0800 Subject: [PATCH 3/6] Minor fixes --- src/compiler/checker.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d9363dc1d816..bce50c821a590 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20036,7 +20036,12 @@ namespace ts { // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper?: TypeMapper, compareTypes?: TypeComparer): Signature { const context = createInferenceContext(signature.typeParameters!, signature, InferenceFlags.None, compareTypes); - const sourceSignature = contextualMapper ? instantiateSignature(contextualSignature, contextualMapper) : contextualSignature; + // We clone the contextualMapper to avoid fixing. For example, when the source signature is (x: T) => T[] and + // the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any') + // for T but leave it possible to later infer '[any]' back to A. + const restType = getEffectiveRestType(contextualSignature); + const mapper = contextualMapper && restType && restType.flags & TypeFlags.TypeParameter ? cloneTypeMapper(contextualMapper) : contextualMapper; + const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature; forEachMatchingParameterType(sourceSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type inferTypes(context.inferences, source, target); @@ -20221,7 +20226,7 @@ namespace ts { // can be specified by users through attributes property. const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node); const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0; - const attributesType = checkExpressionWithContextualType(node.attributes, paramType, undefined, checkMode); + const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode); return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes); } @@ -20257,7 +20262,7 @@ namespace ts { const paramType = getTypeAtPosition(signature, i); const checkMode = (excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) | (excludeArgument ? CheckMode.SkipGenericFunctions : 0); - const argType = checkExpressionWithContextualType(arg, paramType, undefined, checkMode); + const argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ 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 // parameter types yet and therefore excess property checks may yield false positives (see #17041). @@ -21874,7 +21879,7 @@ namespace ts { const functionFlags = getFunctionFlags(func); let type: Type; if (func.body.kind !== SyntaxKind.Block) { - type = checkExpressionCached(func.body, checkMode); + type = checkExpressionCached(func.body, checkMode && checkMode & ~CheckMode.SkipGenericFunctions); if (functionFlags & FunctionFlags.Async) { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so the @@ -22064,7 +22069,7 @@ namespace ts { forEachReturnStatement(func.body, returnStatement => { const expr = returnStatement.expression; if (expr) { - let type = checkExpressionCached(expr, checkMode); + let type = checkExpressionCached(expr, checkMode && checkMode && checkMode & ~CheckMode.SkipGenericFunctions); if (functionFlags & FunctionFlags.Async) { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so the From 91f8fc60f1b0cc42c7842d71ee5fe7a0b2f37595 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 2 Mar 2019 10:34:23 -0800 Subject: [PATCH 4/6] Defer calls to generic functions returning generic functions --- src/compiler/checker.ts | 86 +++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bce50c821a590..a8dccb072b1a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -228,9 +228,9 @@ namespace ts { isContextSensitive, getFullyQualifiedName, getResolvedSignature: (node, candidatesOutArray, agumentCount) => - getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, /*isForSignatureHelp*/ false), + getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, CheckMode.Normal), getResolvedSignatureForSignatureHelp: (node, candidatesOutArray, agumentCount) => - getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, /*isForSignatureHelp*/ true), + getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, CheckMode.IsForSignatureHelp), getConstantValue: nodeIn => { const node = getParseTreeNode(nodeIn, canHaveConstantValue); return node ? getConstantValue(node) : undefined; @@ -374,10 +374,10 @@ namespace ts { getLocalTypeParametersOfClassOrInterfaceOrTypeAlias, }; - function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, isForSignatureHelp: boolean): Signature | undefined { + function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, checkMode: CheckMode): Signature | undefined { const node = getParseTreeNode(nodeIn, isCallLikeExpression); apparentArgumentCount = argumentCount; - const res = node ? getResolvedSignature(node, candidatesOutArray, isForSignatureHelp) : undefined; + const res = node ? getResolvedSignature(node, candidatesOutArray, checkMode) : undefined; apparentArgumentCount = undefined; return res; } @@ -693,6 +693,7 @@ namespace ts { Inferential = 1 << 1, // Inferential typing SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions SkipGenericFunctions = 1 << 3, // Skip single signature generic functions + IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help } const enum CallbackCheck { @@ -20482,7 +20483,7 @@ namespace ts { return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount); } - function resolveCall(node: CallLikeExpression, signatures: ReadonlyArray, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean, fallbackError?: DiagnosticMessage): Signature { + function resolveCall(node: CallLikeExpression, signatures: ReadonlyArray, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode, fallbackError?: DiagnosticMessage): Signature { const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); @@ -20555,7 +20556,7 @@ namespace ts { // If we are in signature help, a trailing comma indicates that we intend to provide another argument, // so we will only accept overloads with arity at least 1 higher than the current number of provided arguments. const signatureHelpTrailingComma = - isForSignatureHelp && node.kind === SyntaxKind.CallExpression && node.arguments.hasTrailingComma; + !!(checkMode & CheckMode.IsForSignatureHelp) && node.kind === SyntaxKind.CallExpression && node.arguments.hasTrailingComma; // Section 4.12.1: // if the candidate list contains one or more signatures for which the type of each argument @@ -20837,7 +20838,7 @@ namespace ts { return maxParamsIndex; } - function resolveCallExpression(node: CallExpression, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveCallExpression(node: CallExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { if (node.expression.kind === SyntaxKind.SuperKeyword) { const superType = checkSuperExpression(node.expression); if (isTypeAny(superType)) { @@ -20852,7 +20853,7 @@ namespace ts { const baseTypeNode = getEffectiveBaseTypeNode(getContainingClass(node)!); if (baseTypeNode) { const baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments, baseTypeNode); - return resolveCall(node, baseConstructors, candidatesOutArray, isForSignatureHelp); + return resolveCall(node, baseConstructors, candidatesOutArray, checkMode); } } return resolveUntypedCall(node); @@ -20912,12 +20913,22 @@ namespace ts { } return resolveErrorCall(node); } + // If we are skipping generic functions (i.e. this call is an argument to another call for which context + // sensitive arguments are being deferred) and every call signature is generic and returns a function type, + // we return resolvingSignature here. This result will be propagated out and turned into anyFunctionType. + if (checkMode & CheckMode.SkipGenericFunctions && callSignatures.every(isGenericFunctionReturningFunction)) { + return resolvingSignature; + } // If the function is explicitly marked with `@class`, then it must be constructed. if (callSignatures.some(sig => isInJSFile(sig.declaration) && !!getJSDocClassTag(sig.declaration!))) { error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); return resolveErrorCall(node); } - return resolveCall(node, callSignatures, candidatesOutArray, isForSignatureHelp); + return resolveCall(node, callSignatures, candidatesOutArray, checkMode); + } + + function isGenericFunctionReturningFunction(signature: Signature) { + return !!(signature.typeParameters && getSingleCallSignature(getReturnTypeOfSignature(signature))); } /** @@ -20931,7 +20942,7 @@ namespace ts { !numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & (TypeFlags.Union | TypeFlags.Never)) && isTypeAssignableTo(funcType, globalFunctionType); } - function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { if (node.arguments && languageVersion < ScriptTarget.ES5) { const spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { @@ -20984,7 +20995,7 @@ namespace ts { return resolveErrorCall(node); } - return resolveCall(node, constructSignatures, candidatesOutArray, isForSignatureHelp); + return resolveCall(node, constructSignatures, candidatesOutArray, checkMode); } // If expressionType's apparent type is an object type with no construct signatures but @@ -20993,7 +21004,7 @@ namespace ts { // operation is Any. It is an error to have a Void this type. const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call); if (callSignatures.length) { - const signature = resolveCall(node, callSignatures, candidatesOutArray, isForSignatureHelp); + const signature = resolveCall(node, callSignatures, candidatesOutArray, checkMode); if (!noImplicitAny) { if (signature.declaration && !isJSConstructor(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { error(node, Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); @@ -21103,7 +21114,7 @@ namespace ts { } } - function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { const tagType = checkExpression(node.tag); const apparentType = getApparentType(tagType); @@ -21124,7 +21135,7 @@ namespace ts { return resolveErrorCall(node); } - return resolveCall(node, callSignatures, candidatesOutArray, isForSignatureHelp); + return resolveCall(node, callSignatures, candidatesOutArray, checkMode); } /** @@ -21155,7 +21166,7 @@ namespace ts { /** * Resolves a decorator as if it were a call expression. */ - function resolveDecorator(node: Decorator, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveDecorator(node: Decorator, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { const funcType = checkExpression(node.expression); const apparentType = getApparentType(funcType); if (apparentType === errorType) { @@ -21184,7 +21195,7 @@ namespace ts { return resolveErrorCall(node); } - return resolveCall(node, callSignatures, candidatesOutArray, isForSignatureHelp, headMessage); + return resolveCall(node, callSignatures, candidatesOutArray, checkMode, headMessage); } function createSignatureForJSXIntrinsic(node: JsxOpeningLikeElement, result: Type): Signature { @@ -21213,7 +21224,7 @@ namespace ts { ); } - function resolveJsxOpeningLikeElement(node: JsxOpeningLikeElement, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveJsxOpeningLikeElement(node: JsxOpeningLikeElement, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { if (isJsxIntrinsicIdentifier(node.tagName)) { const result = getIntrinsicAttributesTypeFromJsxOpeningLikeElement(node); const fakeSignature = createSignatureForJSXIntrinsic(node, result); @@ -21237,7 +21248,7 @@ namespace ts { return resolveErrorCall(node); } - return resolveCall(node, signatures, candidatesOutArray, isForSignatureHelp); + return resolveCall(node, signatures, candidatesOutArray, checkMode); } /** @@ -21252,19 +21263,19 @@ namespace ts { signature.parameters.length < getDecoratorArgumentCount(decorator, signature)); } - function resolveSignature(node: CallLikeExpression, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean): Signature { + function resolveSignature(node: CallLikeExpression, candidatesOutArray: Signature[] | undefined, checkMode: CheckMode): Signature { switch (node.kind) { case SyntaxKind.CallExpression: - return resolveCallExpression(node, candidatesOutArray, isForSignatureHelp); + return resolveCallExpression(node, candidatesOutArray, checkMode); case SyntaxKind.NewExpression: - return resolveNewExpression(node, candidatesOutArray, isForSignatureHelp); + return resolveNewExpression(node, candidatesOutArray, checkMode); case SyntaxKind.TaggedTemplateExpression: - return resolveTaggedTemplateExpression(node, candidatesOutArray, isForSignatureHelp); + return resolveTaggedTemplateExpression(node, candidatesOutArray, checkMode); case SyntaxKind.Decorator: - return resolveDecorator(node, candidatesOutArray, isForSignatureHelp); + return resolveDecorator(node, candidatesOutArray, checkMode); case SyntaxKind.JsxOpeningElement: case SyntaxKind.JsxSelfClosingElement: - return resolveJsxOpeningLikeElement(node, candidatesOutArray, isForSignatureHelp); + return resolveJsxOpeningLikeElement(node, candidatesOutArray, checkMode); } throw Debug.assertNever(node, "Branch in 'resolveSignature' should be unreachable."); } @@ -21276,7 +21287,7 @@ namespace ts { * the function will fill it up with appropriate candidate signatures * @return a signature of the call-like expression or undefined if one can't be found */ - function getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[] | undefined, isForSignatureHelp = false): Signature { + function getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[] | undefined, checkMode?: CheckMode): Signature { const links = getNodeLinks(node); // If getResolvedSignature has already been called, we will have cached the resolvedSignature. // However, it is possible that either candidatesOutArray was not passed in the first time, @@ -21287,11 +21298,15 @@ namespace ts { return cached; } links.resolvedSignature = resolvingSignature; - const result = resolveSignature(node, candidatesOutArray, isForSignatureHelp); - // If signature resolution originated in control flow type analysis (for example to compute the - // assigned type in a flow assignment) we don't cache the result as it may be based on temporary - // types from the control flow analysis. - links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached; + const result = resolveSignature(node, candidatesOutArray, checkMode || CheckMode.Normal); + // When CheckMode.SkipGenericFunctions is set we use resolvingSignature to indicate that call + // resolution should be deferred. + if (result !== resolvingSignature) { + // If signature resolution originated in control flow type analysis (for example to compute the + // assigned type in a flow assignment) we don't cache the result as it may be based on temporary + // types from the control flow analysis. + links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached; + } return result; } @@ -21375,10 +21390,15 @@ namespace ts { * @param node The call/new expression to be checked. * @returns On success, the expression's signature's return type. On failure, anyType. */ - function checkCallExpression(node: CallExpression | NewExpression): Type { + function checkCallExpression(node: CallExpression | NewExpression, checkMode?: CheckMode): Type { if (!checkGrammarTypeArguments(node, node.typeArguments)) checkGrammarArguments(node.arguments); - const signature = getResolvedSignature(node); + const signature = getResolvedSignature(node, /*candidatesOutArray*/ undefined, checkMode); + if (signature === resolvingSignature) { + // CheckMode.SkipGenericFunctions is enabled and this is a call to a generic function that + // returns a function type. We defer checking and return anyFunctionType. + return anyFunctionType; + } if (node.expression.kind === SyntaxKind.SuperKeyword) { return voidType; @@ -23505,7 +23525,7 @@ namespace ts { } /* falls through */ case SyntaxKind.NewExpression: - return checkCallExpression(node); + return checkCallExpression(node, checkMode); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); case SyntaxKind.ParenthesizedExpression: From 304e25cf69a9570234d8c2ad83c1a1f55b086635 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 2 Mar 2019 11:59:33 -0800 Subject: [PATCH 5/6] Add tests --- .../compiler/genericFunctionInference1.ts | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/cases/compiler/genericFunctionInference1.ts diff --git a/tests/cases/compiler/genericFunctionInference1.ts b/tests/cases/compiler/genericFunctionInference1.ts new file mode 100644 index 0000000000000..c5416f32bda26 --- /dev/null +++ b/tests/cases/compiler/genericFunctionInference1.ts @@ -0,0 +1,82 @@ +// @strict: true +// @target: es2015 + +declare function pipe(ab: (...args: A) => B): (...args: A) => B; +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; + +declare function list(a: T): T[]; +declare function box(x: V): { value: V }; + +const f00 = pipe(list); +const f01 = pipe(list, box); +const f02 = pipe(x => list(x), box); +const f03 = pipe(list, x => box(x)); +const f04 = pipe(x => list(x), x => box(x)) +const f05 = pipe(list, pipe(box)); +const f06 = pipe(x => list(x), pipe(box)); +const f07 = pipe(x => list(x), pipe(x => box(x))); + +const f10: (x: T) => T[] = pipe(list); +const f11: (x: T) => { value: T[] } = pipe(list, box); +const f12: (x: T) => { value: T[] } = pipe(x => list(x), box); +const f13: (x: T) => { value: T[] } = pipe(list, x => box(x)); +const f14: (x: T) => { value: T[] } = pipe(x => list(x), x => box(x)) +const f15: (x: T) => { value: T[] } = pipe(list, pipe(box)); +const f16: (x: T) => { value: T[] } = pipe(x => list(x), pipe(box)); +const f17: (x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x))); + +// #29904.2 + +const fn20 = pipe((_a?: {}) => 1); + +// #29904.3 + +type Fn = (n: number) => number; +const fn30: Fn = pipe( + x => x + 1, + x => x * 2, +); + +const promise = Promise.resolve(1); +promise.then( + pipe( + x => x + 1, + x => x * 2, + ), +); + +// #29904.4 + +declare const getString: () => string; +declare const orUndefined: (name: string) => string | undefined; +declare const identity: (value: T) => T; + +const fn40 = pipe( + getString, + string => orUndefined(string), + identity, +); + +// #29904.6 + +declare const getArray: () => string[]; +declare const first: (ts: T[]) => T; + +const fn60 = pipe( + getArray, + x => x, + first, +); + +const fn61 = pipe( + getArray, + identity, + first, +); + +const fn62 = pipe( + getArray, + x => x, + x => first(x), +); From e7881a412ed1ff64f18ecd34486e253e91bece11 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 2 Mar 2019 11:59:41 -0800 Subject: [PATCH 6/6] Accept new baselines --- .../reference/genericFunctionInference1.js | 109 +++++ .../genericFunctionInference1.symbols | 381 +++++++++++++++++ .../reference/genericFunctionInference1.types | 397 ++++++++++++++++++ 3 files changed, 887 insertions(+) create mode 100644 tests/baselines/reference/genericFunctionInference1.js create mode 100644 tests/baselines/reference/genericFunctionInference1.symbols create mode 100644 tests/baselines/reference/genericFunctionInference1.types diff --git a/tests/baselines/reference/genericFunctionInference1.js b/tests/baselines/reference/genericFunctionInference1.js new file mode 100644 index 0000000000000..872656ba9c5c9 --- /dev/null +++ b/tests/baselines/reference/genericFunctionInference1.js @@ -0,0 +1,109 @@ +//// [genericFunctionInference1.ts] +declare function pipe(ab: (...args: A) => B): (...args: A) => B; +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; + +declare function list(a: T): T[]; +declare function box(x: V): { value: V }; + +const f00 = pipe(list); +const f01 = pipe(list, box); +const f02 = pipe(x => list(x), box); +const f03 = pipe(list, x => box(x)); +const f04 = pipe(x => list(x), x => box(x)) +const f05 = pipe(list, pipe(box)); +const f06 = pipe(x => list(x), pipe(box)); +const f07 = pipe(x => list(x), pipe(x => box(x))); + +const f10: (x: T) => T[] = pipe(list); +const f11: (x: T) => { value: T[] } = pipe(list, box); +const f12: (x: T) => { value: T[] } = pipe(x => list(x), box); +const f13: (x: T) => { value: T[] } = pipe(list, x => box(x)); +const f14: (x: T) => { value: T[] } = pipe(x => list(x), x => box(x)) +const f15: (x: T) => { value: T[] } = pipe(list, pipe(box)); +const f16: (x: T) => { value: T[] } = pipe(x => list(x), pipe(box)); +const f17: (x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x))); + +// #29904.2 + +const fn20 = pipe((_a?: {}) => 1); + +// #29904.3 + +type Fn = (n: number) => number; +const fn30: Fn = pipe( + x => x + 1, + x => x * 2, +); + +const promise = Promise.resolve(1); +promise.then( + pipe( + x => x + 1, + x => x * 2, + ), +); + +// #29904.4 + +declare const getString: () => string; +declare const orUndefined: (name: string) => string | undefined; +declare const identity: (value: T) => T; + +const fn40 = pipe( + getString, + string => orUndefined(string), + identity, +); + +// #29904.6 + +declare const getArray: () => string[]; +declare const first: (ts: T[]) => T; + +const fn60 = pipe( + getArray, + x => x, + first, +); + +const fn61 = pipe( + getArray, + identity, + first, +); + +const fn62 = pipe( + getArray, + x => x, + x => first(x), +); + + +//// [genericFunctionInference1.js] +"use strict"; +const f00 = pipe(list); +const f01 = pipe(list, box); +const f02 = pipe(x => list(x), box); +const f03 = pipe(list, x => box(x)); +const f04 = pipe(x => list(x), x => box(x)); +const f05 = pipe(list, pipe(box)); +const f06 = pipe(x => list(x), pipe(box)); +const f07 = pipe(x => list(x), pipe(x => box(x))); +const f10 = pipe(list); +const f11 = pipe(list, box); +const f12 = pipe(x => list(x), box); +const f13 = pipe(list, x => box(x)); +const f14 = pipe(x => list(x), x => box(x)); +const f15 = pipe(list, pipe(box)); +const f16 = pipe(x => list(x), pipe(box)); +const f17 = pipe(x => list(x), pipe(x => box(x))); +// #29904.2 +const fn20 = pipe((_a) => 1); +const fn30 = pipe(x => x + 1, x => x * 2); +const promise = Promise.resolve(1); +promise.then(pipe(x => x + 1, x => x * 2)); +const fn40 = pipe(getString, string => orUndefined(string), identity); +const fn60 = pipe(getArray, x => x, first); +const fn61 = pipe(getArray, identity, first); +const fn62 = pipe(getArray, x => x, x => first(x)); diff --git a/tests/baselines/reference/genericFunctionInference1.symbols b/tests/baselines/reference/genericFunctionInference1.symbols new file mode 100644 index 0000000000000..d49a20cec9c8e --- /dev/null +++ b/tests/baselines/reference/genericFunctionInference1.symbols @@ -0,0 +1,381 @@ +=== tests/cases/compiler/genericFunctionInference1.ts === +declare function pipe(ab: (...args: A) => B): (...args: A) => B; +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 0, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 0, 38)) +>ab : Symbol(ab, Decl(genericFunctionInference1.ts, 0, 42)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 0, 47)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 0, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 0, 38)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 0, 67)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 0, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 0, 38)) + +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 1, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 1, 38)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 1, 41)) +>ab : Symbol(ab, Decl(genericFunctionInference1.ts, 1, 45)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 1, 50)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 1, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 1, 38)) +>bc : Symbol(bc, Decl(genericFunctionInference1.ts, 1, 67)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 1, 73)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 1, 38)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 1, 41)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 1, 87)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 1, 22)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 1, 41)) + +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 2, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 2, 38)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 2, 41)) +>D : Symbol(D, Decl(genericFunctionInference1.ts, 2, 44)) +>ab : Symbol(ab, Decl(genericFunctionInference1.ts, 2, 48)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 2, 53)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 2, 22)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 2, 38)) +>bc : Symbol(bc, Decl(genericFunctionInference1.ts, 2, 70)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 2, 76)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 2, 38)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 2, 41)) +>cd : Symbol(cd, Decl(genericFunctionInference1.ts, 2, 87)) +>c : Symbol(c, Decl(genericFunctionInference1.ts, 2, 93)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 2, 41)) +>D : Symbol(D, Decl(genericFunctionInference1.ts, 2, 44)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 2, 107)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 2, 22)) +>D : Symbol(D, Decl(genericFunctionInference1.ts, 2, 44)) + +declare function list(a: T): T[]; +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 4, 22)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 4, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 4, 22)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 4, 22)) + +declare function box(x: V): { value: V }; +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>V : Symbol(V, Decl(genericFunctionInference1.ts, 5, 21)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 5, 24)) +>V : Symbol(V, Decl(genericFunctionInference1.ts, 5, 21)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 5, 32)) +>V : Symbol(V, Decl(genericFunctionInference1.ts, 5, 21)) + +const f00 = pipe(list); +>f00 : Symbol(f00, Decl(genericFunctionInference1.ts, 7, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) + +const f01 = pipe(list, box); +>f01 : Symbol(f01, Decl(genericFunctionInference1.ts, 8, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f02 = pipe(x => list(x), box); +>f02 : Symbol(f02, Decl(genericFunctionInference1.ts, 9, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 9, 17)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 9, 17)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f03 = pipe(list, x => box(x)); +>f03 : Symbol(f03, Decl(genericFunctionInference1.ts, 10, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 10, 22)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 10, 22)) + +const f04 = pipe(x => list(x), x => box(x)) +>f04 : Symbol(f04, Decl(genericFunctionInference1.ts, 11, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 11, 17)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 11, 17)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 11, 30)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 11, 30)) + +const f05 = pipe(list, pipe(box)); +>f05 : Symbol(f05, Decl(genericFunctionInference1.ts, 12, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f06 = pipe(x => list(x), pipe(box)); +>f06 : Symbol(f06, Decl(genericFunctionInference1.ts, 13, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 13, 17)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 13, 17)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f07 = pipe(x => list(x), pipe(x => box(x))); +>f07 : Symbol(f07, Decl(genericFunctionInference1.ts, 14, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 14, 17)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 14, 17)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 14, 36)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 14, 36)) + +const f10: (x: T) => T[] = pipe(list); +>f10 : Symbol(f10, Decl(genericFunctionInference1.ts, 16, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 16, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 16, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 16, 12)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 16, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) + +const f11: (x: T) => { value: T[] } = pipe(list, box); +>f11 : Symbol(f11, Decl(genericFunctionInference1.ts, 17, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 17, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 17, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 17, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 17, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 17, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f12: (x: T) => { value: T[] } = pipe(x => list(x), box); +>f12 : Symbol(f12, Decl(genericFunctionInference1.ts, 18, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 18, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 18, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 18, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 18, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 18, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 18, 46)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 18, 46)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f13: (x: T) => { value: T[] } = pipe(list, x => box(x)); +>f13 : Symbol(f13, Decl(genericFunctionInference1.ts, 19, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 19, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 19, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 19, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 19, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 19, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 19, 51)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 19, 51)) + +const f14: (x: T) => { value: T[] } = pipe(x => list(x), x => box(x)) +>f14 : Symbol(f14, Decl(genericFunctionInference1.ts, 20, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 20, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 20, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 20, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 20, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 20, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 20, 46)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 20, 46)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 20, 59)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 20, 59)) + +const f15: (x: T) => { value: T[] } = pipe(list, pipe(box)); +>f15 : Symbol(f15, Decl(genericFunctionInference1.ts, 21, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 21, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 21, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 21, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 21, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 21, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f16: (x: T) => { value: T[] } = pipe(x => list(x), pipe(box)); +>f16 : Symbol(f16, Decl(genericFunctionInference1.ts, 22, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 22, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 22, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 22, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 22, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 22, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 22, 46)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 22, 46)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +const f17: (x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x))); +>f17 : Symbol(f17, Decl(genericFunctionInference1.ts, 23, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 23, 12)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 23, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 23, 12)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 23, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 23, 12)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 23, 46)) +>list : Symbol(list, Decl(genericFunctionInference1.ts, 2, 124)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 23, 46)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 23, 65)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 23, 65)) + +// #29904.2 + +const fn20 = pipe((_a?: {}) => 1); +>fn20 : Symbol(fn20, Decl(genericFunctionInference1.ts, 27, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>_a : Symbol(_a, Decl(genericFunctionInference1.ts, 27, 19)) + +// #29904.3 + +type Fn = (n: number) => number; +>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 27, 34)) +>n : Symbol(n, Decl(genericFunctionInference1.ts, 31, 11)) + +const fn30: Fn = pipe( +>fn30 : Symbol(fn30, Decl(genericFunctionInference1.ts, 32, 5)) +>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 27, 34)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + x => x + 1, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 32, 22)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 32, 22)) + + x => x * 2, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 33, 15)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 33, 15)) + +); + +const promise = Promise.resolve(1); +>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 37, 5)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +promise.then( +>promise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 37, 5)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) + + pipe( +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + x => x + 1, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 39, 9)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 39, 9)) + + x => x * 2, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 40, 19)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 40, 19)) + + ), +); + +// #29904.4 + +declare const getString: () => string; +>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 47, 13)) + +declare const orUndefined: (name: string) => string | undefined; +>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 48, 13)) +>name : Symbol(name, Decl(genericFunctionInference1.ts, 48, 28)) + +declare const identity: (value: T) => T; +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 49, 13)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 49, 25)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 49, 28)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 49, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 49, 25)) + +const fn40 = pipe( +>fn40 : Symbol(fn40, Decl(genericFunctionInference1.ts, 51, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + getString, +>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 47, 13)) + + string => orUndefined(string), +>string : Symbol(string, Decl(genericFunctionInference1.ts, 52, 14)) +>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 48, 13)) +>string : Symbol(string, Decl(genericFunctionInference1.ts, 52, 14)) + + identity, +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 49, 13)) + +); + +// #29904.6 + +declare const getArray: () => string[]; +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 59, 13)) + +declare const first: (ts: T[]) => T; +>first : Symbol(first, Decl(genericFunctionInference1.ts, 60, 13)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 22)) +>ts : Symbol(ts, Decl(genericFunctionInference1.ts, 60, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 22)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 60, 22)) + +const fn60 = pipe( +>fn60 : Symbol(fn60, Decl(genericFunctionInference1.ts, 62, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + getArray, +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 59, 13)) + + x => x, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 63, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 63, 13)) + + first, +>first : Symbol(first, Decl(genericFunctionInference1.ts, 60, 13)) + +); + +const fn61 = pipe( +>fn61 : Symbol(fn61, Decl(genericFunctionInference1.ts, 68, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + getArray, +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 59, 13)) + + identity, +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 49, 13)) + + first, +>first : Symbol(first, Decl(genericFunctionInference1.ts, 60, 13)) + +); + +const fn62 = pipe( +>fn62 : Symbol(fn62, Decl(genericFunctionInference1.ts, 74, 5)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) + + getArray, +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 59, 13)) + + x => x, +>x : Symbol(x, Decl(genericFunctionInference1.ts, 75, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 75, 13)) + + x => first(x), +>x : Symbol(x, Decl(genericFunctionInference1.ts, 76, 11)) +>first : Symbol(first, Decl(genericFunctionInference1.ts, 60, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 76, 11)) + +); + diff --git a/tests/baselines/reference/genericFunctionInference1.types b/tests/baselines/reference/genericFunctionInference1.types new file mode 100644 index 0000000000000..037e4a4971862 --- /dev/null +++ b/tests/baselines/reference/genericFunctionInference1.types @@ -0,0 +1,397 @@ +=== tests/cases/compiler/genericFunctionInference1.ts === +declare function pipe(ab: (...args: A) => B): (...args: A) => B; +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>ab : (...args: A) => B +>args : A +>args : A + +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>ab : (...args: A) => B +>args : A +>bc : (b: B) => C +>b : B +>args : A + +declare function pipe(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>ab : (...args: A) => B +>args : A +>bc : (b: B) => C +>b : B +>cd : (c: C) => D +>c : C +>args : A + +declare function list(a: T): T[]; +>list : (a: T) => T[] +>a : T + +declare function box(x: V): { value: V }; +>box : (x: V) => { value: V; } +>x : V +>value : V + +const f00 = pipe(list); +>f00 : (a: any) => any[] +>pipe(list) : (a: any) => any[] +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] + +const f01 = pipe(list, box); +>f01 : (a: any) => { value: any[]; } +>pipe(list, box) : (a: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>box : (x: V) => { value: V; } + +const f02 = pipe(x => list(x), box); +>f02 : (x: any) => { value: any[]; } +>pipe(x => list(x), box) : (x: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: any) => any[] +>x : any +>list(x) : any[] +>list : (a: T) => T[] +>x : any +>box : (x: V) => { value: V; } + +const f03 = pipe(list, x => box(x)); +>f03 : (a: any) => { value: any[]; } +>pipe(list, x => box(x)) : (a: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>x => box(x) : (x: any[]) => { value: any[]; } +>x : any[] +>box(x) : { value: any[]; } +>box : (x: V) => { value: V; } +>x : any[] + +const f04 = pipe(x => list(x), x => box(x)) +>f04 : (x: any) => { value: any[]; } +>pipe(x => list(x), x => box(x)) : (x: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: any) => any[] +>x : any +>list(x) : any[] +>list : (a: T) => T[] +>x : any +>x => box(x) : (x: any[]) => { value: any[]; } +>x : any[] +>box(x) : { value: any[]; } +>box : (x: V) => { value: V; } +>x : any[] + +const f05 = pipe(list, pipe(box)); +>f05 : (a: any) => { value: any[]; } +>pipe(list, pipe(box)) : (a: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>pipe(box) : (x: any[]) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>box : (x: V) => { value: V; } + +const f06 = pipe(x => list(x), pipe(box)); +>f06 : (x: any) => { value: any[]; } +>pipe(x => list(x), pipe(box)) : (x: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: any) => any[] +>x : any +>list(x) : any[] +>list : (a: T) => T[] +>x : any +>pipe(box) : (x: any[]) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>box : (x: V) => { value: V; } + +const f07 = pipe(x => list(x), pipe(x => box(x))); +>f07 : (x: any) => { value: any[]; } +>pipe(x => list(x), pipe(x => box(x))) : (x: any) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: any) => any[] +>x : any +>list(x) : any[] +>list : (a: T) => T[] +>x : any +>pipe(x => box(x)) : (x: any[]) => { value: any[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => box(x) : (x: any[]) => { value: any[]; } +>x : any[] +>box(x) : { value: any[]; } +>box : (x: V) => { value: V; } +>x : any[] + +const f10: (x: T) => T[] = pipe(list); +>f10 : (x: T) => T[] +>x : T +>pipe(list) : (a: T) => T[] +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] + +const f11: (x: T) => { value: T[] } = pipe(list, box); +>f11 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(list, box) : (a: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>box : (x: V) => { value: V; } + +const f12: (x: T) => { value: T[] } = pipe(x => list(x), box); +>f12 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(x => list(x), box) : (x: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: T) => T[] +>x : T +>list(x) : T[] +>list : (a: T) => T[] +>x : T +>box : (x: V) => { value: V; } + +const f13: (x: T) => { value: T[] } = pipe(list, x => box(x)); +>f13 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(list, x => box(x)) : (a: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>x => box(x) : (x: T[]) => { value: T[]; } +>x : T[] +>box(x) : { value: T[]; } +>box : (x: V) => { value: V; } +>x : T[] + +const f14: (x: T) => { value: T[] } = pipe(x => list(x), x => box(x)) +>f14 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(x => list(x), x => box(x)) : (x: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: T) => T[] +>x : T +>list(x) : T[] +>list : (a: T) => T[] +>x : T +>x => box(x) : (x: T[]) => { value: T[]; } +>x : T[] +>box(x) : { value: T[]; } +>box : (x: V) => { value: V; } +>x : T[] + +const f15: (x: T) => { value: T[] } = pipe(list, pipe(box)); +>f15 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(list, pipe(box)) : (a: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list : (a: T) => T[] +>pipe(box) : (x: T[]) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>box : (x: V) => { value: V; } + +const f16: (x: T) => { value: T[] } = pipe(x => list(x), pipe(box)); +>f16 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(x => list(x), pipe(box)) : (x: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: T) => T[] +>x : T +>list(x) : T[] +>list : (a: T) => T[] +>x : T +>pipe(box) : (x: T[]) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>box : (x: V) => { value: V; } + +const f17: (x: T) => { value: T[] } = pipe(x => list(x), pipe(x => box(x))); +>f17 : (x: T) => { value: T[]; } +>x : T +>value : T[] +>pipe(x => list(x), pipe(x => box(x))) : (x: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => list(x) : (x: T) => T[] +>x : T +>list(x) : T[] +>list : (a: T) => T[] +>x : T +>pipe(x => box(x)) : (x: T[]) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>x => box(x) : (x: T[]) => { value: T[]; } +>x : T[] +>box(x) : { value: T[]; } +>box : (x: V) => { value: V; } +>x : T[] + +// #29904.2 + +const fn20 = pipe((_a?: {}) => 1); +>fn20 : (_a?: {} | undefined) => number +>pipe((_a?: {}) => 1) : (_a?: {} | undefined) => number +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>(_a?: {}) => 1 : (_a?: {} | undefined) => number +>_a : {} | undefined +>1 : 1 + +// #29904.3 + +type Fn = (n: number) => number; +>Fn : Fn +>n : number + +const fn30: Fn = pipe( +>fn30 : Fn +>pipe( x => x + 1, x => x * 2,) : (x: number) => number +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + x => x + 1, +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + x => x * 2, +>x => x * 2 : (x: number) => number +>x : number +>x * 2 : number +>x : number +>2 : 2 + +); + +const promise = Promise.resolve(1); +>promise : Promise +>Promise.resolve(1) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>1 : 1 + +promise.then( +>promise.then( pipe( x => x + 1, x => x * 2, ),) : Promise +>promise.then : (onfulfilled?: ((value: number) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined) => Promise +>promise : Promise +>then : (onfulfilled?: ((value: number) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined) => Promise + + pipe( +>pipe( x => x + 1, x => x * 2, ) : (x: number) => number +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + x => x + 1, +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + x => x * 2, +>x => x * 2 : (x: number) => number +>x : number +>x * 2 : number +>x : number +>2 : 2 + + ), +); + +// #29904.4 + +declare const getString: () => string; +>getString : () => string + +declare const orUndefined: (name: string) => string | undefined; +>orUndefined : (name: string) => string | undefined +>name : string + +declare const identity: (value: T) => T; +>identity : (value: T) => T +>value : T + +const fn40 = pipe( +>fn40 : () => string | undefined +>pipe( getString, string => orUndefined(string), identity,) : () => string | undefined +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + getString, +>getString : () => string + + string => orUndefined(string), +>string => orUndefined(string) : (string: string) => string | undefined +>string : string +>orUndefined(string) : string | undefined +>orUndefined : (name: string) => string | undefined +>string : string + + identity, +>identity : (value: T) => T + +); + +// #29904.6 + +declare const getArray: () => string[]; +>getArray : () => string[] + +declare const first: (ts: T[]) => T; +>first : (ts: T[]) => T +>ts : T[] + +const fn60 = pipe( +>fn60 : () => string +>pipe( getArray, x => x, first,) : () => string +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + getArray, +>getArray : () => string[] + + x => x, +>x => x : (x: string[]) => string[] +>x : string[] +>x : string[] + + first, +>first : (ts: T[]) => T + +); + +const fn61 = pipe( +>fn61 : () => string +>pipe( getArray, identity, first,) : () => string +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + getArray, +>getArray : () => string[] + + identity, +>identity : (value: T) => T + + first, +>first : (ts: T[]) => T + +); + +const fn62 = pipe( +>fn62 : () => string +>pipe( getArray, x => x, x => first(x),) : () => string +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } + + getArray, +>getArray : () => string[] + + x => x, +>x => x : (x: string[]) => string[] +>x : string[] +>x : string[] + + x => first(x), +>x => first(x) : (x: string[]) => string +>x : string[] +>first(x) : string +>first : (ts: T[]) => T +>x : string[] + +); +