mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Infer from annotated return type nodes before assigning contextual parameter types (#60964)
This commit is contained in:
committed by
GitHub
parent
12c232333b
commit
0d016920e6
@@ -37870,7 +37870,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
|
||||
}
|
||||
|
||||
function inferFromAnnotatedParameters(signature: Signature, context: Signature, inferenceContext: InferenceContext) {
|
||||
function inferFromAnnotatedParametersAndReturn(signature: Signature, context: Signature, inferenceContext: InferenceContext) {
|
||||
const len = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const declaration = signature.parameters[i].valueDeclaration as ParameterDeclaration;
|
||||
@@ -37881,6 +37881,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
inferTypes(inferenceContext.inferences, source, target);
|
||||
}
|
||||
}
|
||||
const typeNode = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
|
||||
if (typeNode) {
|
||||
const source = getTypeFromTypeNode(typeNode);
|
||||
const target = getReturnTypeOfSignature(context);
|
||||
inferTypes(inferenceContext.inferences, source, target);
|
||||
}
|
||||
}
|
||||
|
||||
function assignContextualParameterTypes(signature: Signature, context: Signature) {
|
||||
@@ -38878,7 +38884,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const inferenceContext = getInferenceContext(node);
|
||||
let instantiatedContextualSignature: Signature | undefined;
|
||||
if (checkMode && checkMode & CheckMode.Inferential) {
|
||||
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext!);
|
||||
inferFromAnnotatedParametersAndReturn(signature, contextualSignature, inferenceContext!);
|
||||
const restType = getEffectiveRestType(contextualSignature);
|
||||
if (restType && restType.flags & TypeFlags.TypeParameter) {
|
||||
instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext!.nonFixingMapper);
|
||||
@@ -38896,7 +38902,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
else if (contextualSignature && !node.typeParameters && contextualSignature.parameters.length > node.parameters.length) {
|
||||
const inferenceContext = getInferenceContext(node);
|
||||
if (checkMode && checkMode & CheckMode.Inferential) {
|
||||
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext!);
|
||||
inferFromAnnotatedParametersAndReturn(signature, contextualSignature, inferenceContext!);
|
||||
}
|
||||
}
|
||||
if (contextualSignature && !getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
|
||||
|
||||
Reference in New Issue
Block a user