diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9d61d221b1f..c87062a212f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16703,8 +16703,9 @@ namespace ts { } } if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { + // parameter might be a transient symbol generated by use of `arguments` in the function body. const parameter = lastOrUndefined(signature.parameters); - if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { + if (isTransientSymbol(parameter) || !getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); } diff --git a/tests/baselines/reference/contextuallyTypeArgumentsKeyword.symbols b/tests/baselines/reference/contextuallyTypeArgumentsKeyword.symbols new file mode 100644 index 00000000000..556c362f27e --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeArgumentsKeyword.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/foo.js === +// Repro for #16585 +const x = { +>x : Symbol(x, Decl(foo.js, 1, 5)) + + bar() { +>bar : Symbol(bar, Decl(foo.js, 1, 11)) + + setTimeout(function() { arguments }, 0); +>setTimeout : Symbol(setTimeout, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>arguments : Symbol(arguments) + } +} + diff --git a/tests/baselines/reference/contextuallyTypeArgumentsKeyword.types b/tests/baselines/reference/contextuallyTypeArgumentsKeyword.types new file mode 100644 index 00000000000..2f90f47f370 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeArgumentsKeyword.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/foo.js === +// Repro for #16585 +const x = { +>x : { [x: string]: any; bar(): void; } +>{ bar() { setTimeout(function() { arguments }, 0); }} : { [x: string]: any; bar(): void; } + + bar() { +>bar : () => void + + setTimeout(function() { arguments }, 0); +>setTimeout(function() { arguments }, 0) : number +>setTimeout : { (handler: (...args: any[]) => void, timeout: number): number; (handler: any, timeout?: any, ...args: any[]): number; } +>function() { arguments } : (...args: any[]) => void +>arguments : IArguments +>0 : 0 + } +} + diff --git a/tests/cases/compiler/contextuallyTypeArgumentsKeyword.ts b/tests/cases/compiler/contextuallyTypeArgumentsKeyword.ts new file mode 100644 index 00000000000..9421e70c4e8 --- /dev/null +++ b/tests/cases/compiler/contextuallyTypeArgumentsKeyword.ts @@ -0,0 +1,11 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @lib: es2017, dom +// @Filename: foo.js +// Repro for #16585 +const x = { + bar() { + setTimeout(function() { arguments }, 0); + } +}