Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Infer rest type without using assignContextualParameterTypes
  • Loading branch information
jakebailey committed Jun 29, 2022
commit 25bdb8a68709b4443a96fd044f9913e145f71e12
14 changes: 8 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32475,13 +32475,15 @@ namespace ts {
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.
// signature (without fixing type parameters) and infer types without calling assignContextualParameterTypes
// (which would fix parameter types).
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);
const instantiatedRestType = getEffectiveRestType(instantiatedContext);
if (instantiatedRestType) {
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, len), instantiatedRestType);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/getParameterNameAtPosition.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock
cases(fn(opts => { }));
>cases(fn(opts => { })) : void
>cases : (tester: Tester) => void
>fn(opts => { }) : Mock<[opts: any]>
>fn(opts => { }) : Mock<[opts: any, done: (...args: any[]) => any]>
>fn : <Y extends any[]>(implementation?: ((...args: Y) => any) | undefined) => Mock<Y>
>opts => { } : (opts: any) => void
>opts : any
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/issue49383.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [issue49383.ts]
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
wrap(({ cancelable } = {}) => {});


//// [issue49383.js]
function wrap(_) { }
wrap(function (_a) {
var _b = _a === void 0 ? {} : _a, cancelable = _b.cancelable;
});
12 changes: 12 additions & 0 deletions tests/baselines/reference/issue49383.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/issue49383.ts ===
function wrap<Args extends unknown[]>(_: (...args: Args) => void) {}
>wrap : Symbol(wrap, Decl(issue49383.ts, 0, 0))
>Args : Symbol(Args, Decl(issue49383.ts, 0, 14))
>_ : Symbol(_, Decl(issue49383.ts, 0, 38))
>args : Symbol(args, Decl(issue49383.ts, 0, 42))
>Args : Symbol(Args, Decl(issue49383.ts, 0, 14))

wrap(({ cancelable } = {}) => {});
>wrap : Symbol(wrap, Decl(issue49383.ts, 0, 0))
>cancelable : Symbol(cancelable, Decl(issue49383.ts, 1, 7))

13 changes: 13 additions & 0 deletions tests/baselines/reference/issue49383.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/issue49383.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
>{} : {}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function consumeClass(c: GenericClass<[string, boolean]>) { }
consumeClass(createClass(str => console.log(str.length)));
>consumeClass(createClass(str => console.log(str.length))) : void
>consumeClass : (c: GenericClass<[string, boolean]>) => void
>createClass(str => console.log(str.length)) : GenericClass<[str: string]>
>createClass(str => console.log(str.length)) : GenericClass<[string, boolean]>
>createClass : <T extends MyTuple>(f: GenericFunction<T>) => GenericClass<T>
>str => console.log(str.length) : (str: string) => void
>str : string
Expand All @@ -49,7 +49,7 @@ consumeClass(createClass(str => console.log(str.length)));
consumeClass(createClass((str, _unused_num) => console.log(str.length)));
>consumeClass(createClass((str, _unused_num) => console.log(str.length))) : void
>consumeClass : (c: GenericClass<[string, boolean]>) => void
>createClass((str, _unused_num) => console.log(str.length)) : GenericClass<[str: string, _unused_num: boolean]>
>createClass((str, _unused_num) => console.log(str.length)) : GenericClass<[string, boolean]>
>createClass : <T extends MyTuple>(f: GenericFunction<T>) => GenericClass<T>
>(str, _unused_num) => console.log(str.length) : (str: string, _unused_num: boolean) => void
>str : string
Expand Down