diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8a94458228e..d316aec55fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -40289,9 +40289,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const containsArguments = containsArgumentsReference(node); if (containsArguments) { - const lastJSDocParam = lastOrUndefined(jsdocParameters); + const lastJSDocParamIndex = jsdocParameters.length - 1; + const lastJSDocParam = jsdocParameters[lastJSDocParamIndex]; if (isJs && lastJSDocParam && isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression && - lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) { + lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !excludedParameters.has(lastJSDocParamIndex) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) { error(lastJSDocParam.name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, idText(lastJSDocParam.name)); } } diff --git a/tests/baselines/reference/jsdocParamTag2.errors.txt b/tests/baselines/reference/jsdocParamTag2.errors.txt index cb95ce14319..0b5a5da6ece 100644 --- a/tests/baselines/reference/jsdocParamTag2.errors.txt +++ b/tests/baselines/reference/jsdocParamTag2.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/jsdoc/0.js(61,19): error TS2339: Property 'a' does not exist on type 'String'. -tests/cases/conformance/jsdoc/0.js(61,22): error TS2339: Property 'b' does not exist on type 'String'. -tests/cases/conformance/jsdoc/0.js(63,20): error TS8024: JSDoc '@param' tag has name 'y', but there is no parameter with that name. +tests/cases/conformance/jsdoc/0.js(68,19): error TS2339: Property 'a' does not exist on type 'String'. +tests/cases/conformance/jsdoc/0.js(68,22): error TS2339: Property 'b' does not exist on type 'String'. +tests/cases/conformance/jsdoc/0.js(70,20): error TS8024: JSDoc '@param' tag has name 'y', but there is no parameter with that name. ==== tests/cases/conformance/jsdoc/0.js (3 errors) ==== @@ -58,6 +58,13 @@ tests/cases/conformance/jsdoc/0.js(63,20): error TS8024: JSDoc '@param' tag has */ function good8({a, b}) {} + /** + * @param {{ a: string }} argument + */ + function good9({ a }) { + console.log(arguments, a); + } + /** * @param {object} obj - this type gets ignored * @param {string} obj.a diff --git a/tests/baselines/reference/jsdocParamTag2.symbols b/tests/baselines/reference/jsdocParamTag2.symbols index 15eea8946e1..b7a287fa2f0 100644 --- a/tests/baselines/reference/jsdocParamTag2.symbols +++ b/tests/baselines/reference/jsdocParamTag2.symbols @@ -93,6 +93,21 @@ function good8({a, b}) {} >a : Symbol(a, Decl(0.js, 52, 16)) >b : Symbol(b, Decl(0.js, 52, 18)) +/** + * @param {{ a: string }} argument + */ +function good9({ a }) { +>good9 : Symbol(good9, Decl(0.js, 52, 25)) +>a : Symbol(a, Decl(0.js, 57, 16)) + + console.log(arguments, a); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>arguments : Symbol(arguments) +>a : Symbol(a, Decl(0.js, 57, 16)) +} + /** * @param {object} obj - this type gets ignored * @param {string} obj.a @@ -100,18 +115,18 @@ function good8({a, b}) {} * @param {string} x */ function bad1(x, {a, b}) {} ->bad1 : Symbol(bad1, Decl(0.js, 52, 25)) ->x : Symbol(x, Decl(0.js, 60, 14)) ->a : Symbol(a, Decl(0.js, 60, 18)) ->b : Symbol(b, Decl(0.js, 60, 20)) +>bad1 : Symbol(bad1, Decl(0.js, 59, 1)) +>x : Symbol(x, Decl(0.js, 67, 14)) +>a : Symbol(a, Decl(0.js, 67, 18)) +>b : Symbol(b, Decl(0.js, 67, 20)) /** * @param {string} y - here, y's type gets ignored but obj's is fine * @param {{a: string, b: string}} obj */ function bad2(x, {a, b}) {} ->bad2 : Symbol(bad2, Decl(0.js, 60, 27)) ->x : Symbol(x, Decl(0.js, 65, 14)) ->a : Symbol(a, Decl(0.js, 65, 18)) ->b : Symbol(b, Decl(0.js, 65, 20)) +>bad2 : Symbol(bad2, Decl(0.js, 67, 27)) +>x : Symbol(x, Decl(0.js, 72, 14)) +>a : Symbol(a, Decl(0.js, 72, 18)) +>b : Symbol(b, Decl(0.js, 72, 20)) diff --git a/tests/baselines/reference/jsdocParamTag2.types b/tests/baselines/reference/jsdocParamTag2.types index e81155ccb3c..bcd326a8484 100644 --- a/tests/baselines/reference/jsdocParamTag2.types +++ b/tests/baselines/reference/jsdocParamTag2.types @@ -93,6 +93,22 @@ function good8({a, b}) {} >a : string >b : string +/** + * @param {{ a: string }} argument + */ +function good9({ a }) { +>good9 : ({ a }: { a: string;}, ...args: any[]) => void +>a : string + + console.log(arguments, a); +>console.log(arguments, a) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>arguments : IArguments +>a : string +} + /** * @param {object} obj - this type gets ignored * @param {string} obj.a diff --git a/tests/cases/conformance/jsdoc/jsdocParamTag2.ts b/tests/cases/conformance/jsdoc/jsdocParamTag2.ts index e9ebbe050c8..0d34ee5496a 100644 --- a/tests/cases/conformance/jsdoc/jsdocParamTag2.ts +++ b/tests/cases/conformance/jsdoc/jsdocParamTag2.ts @@ -57,6 +57,13 @@ function good7(x, {a, b}, y) {} */ function good8({a, b}) {} +/** + * @param {{ a: string }} argument + */ +function good9({ a }) { + console.log(arguments, a); +} + /** * @param {object} obj - this type gets ignored * @param {string} obj.a