Infer rest type without using assignContextualParameterTypes (#49740)

This commit is contained in:
Jake Bailey
2022-07-06 11:27:56 -04:00
committed by GitHub
parent e75b25a444
commit 641ab8eb97
5 changed files with 43 additions and 12 deletions

View File

@@ -32553,17 +32553,6 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
}
}
}
const restType = getEffectiveRestType(context);
if (restType && restType.flags & TypeFlags.TypeParameter) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
const instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
const restPos = getParameterCount(context) - 1;
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature: Signature, context: Signature) {
@@ -33079,10 +33068,15 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
if (isContextSensitive(node)) {
if (contextualSignature) {
const inferenceContext = getInferenceContext(node);
let instantiatedContextualSignature: Signature | undefined;
if (checkMode && checkMode & CheckMode.Inferential) {
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext!);
const restType = getEffectiveRestType(contextualSignature);
if (restType && restType.flags & TypeFlags.TypeParameter) {
instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext!.nonFixingMapper);
}
}
const instantiatedContextualSignature = inferenceContext ?
instantiatedContextualSignature ||= inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}