mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 22:32:33 -05:00
Infer rest type without using assignContextualParameterTypes (#49740)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user