mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Infer rest type without using assignContextualParameterTypes (#49740)
This commit is contained in:
parent
e75b25a444
commit
641ab8eb97
@ -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);
|
||||
}
|
||||
|
||||
10
tests/baselines/reference/inferredRestTypeFixedOnce.js
Normal file
10
tests/baselines/reference/inferredRestTypeFixedOnce.js
Normal file
@ -0,0 +1,10 @@
|
||||
//// [inferredRestTypeFixedOnce.ts]
|
||||
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
|
||||
wrap(({ cancelable } = {}) => {});
|
||||
|
||||
|
||||
//// [inferredRestTypeFixedOnce.js]
|
||||
function wrap(_) { }
|
||||
wrap(function (_a) {
|
||||
var _b = _a === void 0 ? {} : _a, cancelable = _b.cancelable;
|
||||
});
|
||||
12
tests/baselines/reference/inferredRestTypeFixedOnce.symbols
Normal file
12
tests/baselines/reference/inferredRestTypeFixedOnce.symbols
Normal file
@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/inferredRestTypeFixedOnce.ts ===
|
||||
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
|
||||
>wrap : Symbol(wrap, Decl(inferredRestTypeFixedOnce.ts, 0, 0))
|
||||
>Args : Symbol(Args, Decl(inferredRestTypeFixedOnce.ts, 0, 14))
|
||||
>_ : Symbol(_, Decl(inferredRestTypeFixedOnce.ts, 0, 38))
|
||||
>args : Symbol(args, Decl(inferredRestTypeFixedOnce.ts, 0, 42))
|
||||
>Args : Symbol(Args, Decl(inferredRestTypeFixedOnce.ts, 0, 14))
|
||||
|
||||
wrap(({ cancelable } = {}) => {});
|
||||
>wrap : Symbol(wrap, Decl(inferredRestTypeFixedOnce.ts, 0, 0))
|
||||
>cancelable : Symbol(cancelable, Decl(inferredRestTypeFixedOnce.ts, 1, 7))
|
||||
|
||||
13
tests/baselines/reference/inferredRestTypeFixedOnce.types
Normal file
13
tests/baselines/reference/inferredRestTypeFixedOnce.types
Normal file
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/inferredRestTypeFixedOnce.ts ===
|
||||
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
|
||||
>wrap : <Args extends unknown[]>(_: (...args: Args) => void) => void
|
||||
>_ : (...args: Args) => void
|
||||
>args : Args
|
||||
|
||||
wrap(({ cancelable } = {}) => {});
|
||||
>wrap(({ cancelable } = {}) => {}) : void
|
||||
>wrap : <Args extends unknown[]>(_: (...args: Args) => void) => void
|
||||
>({ cancelable } = {}) => {} : ({ cancelable }?: { cancelable: any; }) => void
|
||||
>cancelable : any
|
||||
>{} : {}
|
||||
|
||||
2
tests/cases/compiler/inferredRestTypeFixedOnce.ts
Normal file
2
tests/cases/compiler/inferredRestTypeFixedOnce.ts
Normal file
@ -0,0 +1,2 @@
|
||||
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
|
||||
wrap(({ cancelable } = {}) => {});
|
||||
Loading…
x
Reference in New Issue
Block a user