From b3bebe391de6dd675f1d58525d9eee5b554adec5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 18:23:15 +0000 Subject: [PATCH] Fix isolated declarations to not flag function expressions in call arguments Function expressions and arrow functions used as arguments to function calls were incorrectly being flagged for needing explicit return type annotations with --isolatedDeclarations. This change modifies the logic in expressionToTypeNode.ts to skip inference fallback reporting for function expressions that are direct arguments to call expressions. The fix addresses the underlying issue by checking if the function expression's parent is a CallExpression and passing reportFallback=false in those cases, preventing the inference fallback error from being generated in the first place. Fixes #62085 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com> --- src/compiler/expressionToTypeNode.ts | 7 ++++++- src/compiler/transformers/declarations.ts | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 0df3a399b8f..10cdb4bbc2c 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -731,6 +731,9 @@ export function createSyntacticTypeNodeBuilder( case SyntaxKind.ConstructorType: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: + // Don't report inference fallback for function expressions that are arguments to call expressions + const shouldReportFallback = !(node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction) || !isCallExpression(node.parent); + return createReturnFromSignature(node, symbol, context, shouldReportFallback); case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocSignature: return createReturnFromSignature(node, symbol, context); @@ -968,7 +971,9 @@ export function createSyntacticTypeNodeBuilder( return failed; } function typeFromFunctionLikeExpression(fnNode: FunctionExpression | ArrowFunction, context: SyntacticTypeNodeBuilderContext) { - const returnType = createReturnFromSignature(fnNode, /*symbol*/ undefined, context); + // Don't report inference fallback for function expressions that are arguments to call expressions + const shouldReportFallback = !isCallExpression(fnNode.parent); + const returnType = createReturnFromSignature(fnNode, /*symbol*/ undefined, context, shouldReportFallback); const typeParameters = reuseTypeParameters(fnNode.typeParameters, context); const parameters = fnNode.parameters.map(p => ensureParameter(p, context)); return syntacticResult( diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 08a88dc776e..4b6941dc61f 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -94,7 +94,6 @@ import { isBinaryExpression, isBindingElement, isBindingPattern, - isCallExpression, isClassDeclaration, isClassElement, isComputedPropertyName, @@ -332,13 +331,6 @@ export function transformDeclarations(context: TransformationContext): Transform reportExpandoFunctionErrors(node); } else { - // Don't report errors for function expressions that are arguments to call expressions - if ( - (node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction) && - isCallExpression(node.parent) - ) { - return; - } context.addDiagnostic(getIsolatedDeclarationError(node)); } }