mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Only parameterless arrow functions have early stage inference from return type
This commit is contained in:
@@ -7136,7 +7136,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
// Use contextual parameter type if one is available
|
||||
const type = declaration.symbol.escapedName === InternalSymbolName.This ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration, /*forCache*/ true);
|
||||
const type = declaration.symbol.escapedName === InternalSymbolName.This ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration, /*forCache*/ false);
|
||||
if (type) {
|
||||
return addOptionality(type, isOptional);
|
||||
}
|
||||
@@ -26430,14 +26430,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | MethodDeclaration, checkMode?: CheckMode): Type {
|
||||
function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | ArrowFunction | MethodDeclaration, checkMode?: CheckMode): Type {
|
||||
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
|
||||
checkNodeDeferred(node);
|
||||
|
||||
// The identityMapper object is used to indicate that function expressions are wildcards
|
||||
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)) {
|
||||
if (!getEffectiveReturnTypeNode(node) && node.kind === SyntaxKind.ArrowFunction && node.parameters.length === 0) {
|
||||
// Return plain anyFunctionType if there is no possibility we'll make inferences from the return type
|
||||
const contextualSignature = getContextualSignature(node);
|
||||
if (contextualSignature && couldContainTypeVariables(getReturnTypeOfSignature(contextualSignature))) {
|
||||
|
||||
Reference in New Issue
Block a user