Skip to content

Commit 2fbc225

Browse files
authored
Merge pull request #18392 from Microsoft/fix-contextually-typing-arguments-object
Fix contextually typing arguments object
2 parents 1f0e7b0 + 4e04a74 commit 2fbc225

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16703,8 +16703,9 @@ namespace ts {
1670316703
}
1670416704
}
1670516705
if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) {
16706+
// parameter might be a transient symbol generated by use of `arguments` in the function body.
1670616707
const parameter = lastOrUndefined(signature.parameters);
16707-
if (!getEffectiveTypeAnnotationNode(<ParameterDeclaration>parameter.valueDeclaration)) {
16708+
if (isTransientSymbol(parameter) || !getEffectiveTypeAnnotationNode(<ParameterDeclaration>parameter.valueDeclaration)) {
1670816709
const contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters));
1670916710
assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType);
1671016711
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/foo.js ===
2+
// Repro for #16585
3+
const x = {
4+
>x : Symbol(x, Decl(foo.js, 1, 5))
5+
6+
bar() {
7+
>bar : Symbol(bar, Decl(foo.js, 1, 11))
8+
9+
setTimeout(function() { arguments }, 0);
10+
>setTimeout : Symbol(setTimeout, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
11+
>arguments : Symbol(arguments)
12+
}
13+
}
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/foo.js ===
2+
// Repro for #16585
3+
const x = {
4+
>x : { [x: string]: any; bar(): void; }
5+
>{ bar() { setTimeout(function() { arguments }, 0); }} : { [x: string]: any; bar(): void; }
6+
7+
bar() {
8+
>bar : () => void
9+
10+
setTimeout(function() { arguments }, 0);
11+
>setTimeout(function() { arguments }, 0) : number
12+
>setTimeout : { (handler: (...args: any[]) => void, timeout: number): number; (handler: any, timeout?: any, ...args: any[]): number; }
13+
>function() { arguments } : (...args: any[]) => void
14+
>arguments : IArguments
15+
>0 : 0
16+
}
17+
}
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @lib: es2017, dom
5+
// @Filename: foo.js
6+
// Repro for #16585
7+
const x = {
8+
bar() {
9+
setTimeout(function() { arguments }, 0);
10+
}
11+
}

0 commit comments

Comments
 (0)