mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-03 18:38:40 -06:00
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>
This commit is contained in:
parent
f163c167b7
commit
b3bebe391d
@ -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(
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user