Skip to content

Commit 5016d13

Browse files
authored
fix(51112): skip checking binding parameters for functions that contains arguments (microsoft#51258)
1 parent fbdf00c commit 5016d13

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40289,9 +40289,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4028940289

4029040290
const containsArguments = containsArgumentsReference(node);
4029140291
if (containsArguments) {
40292-
const lastJSDocParam = lastOrUndefined(jsdocParameters);
40292+
const lastJSDocParamIndex = jsdocParameters.length - 1;
40293+
const lastJSDocParam = jsdocParameters[lastJSDocParamIndex];
4029340294
if (isJs && lastJSDocParam && isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression &&
40294-
lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) {
40295+
lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !excludedParameters.has(lastJSDocParamIndex) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) {
4029540296
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));
4029640297
}
4029740298
}

tests/baselines/reference/jsdocParamTag2.errors.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/conformance/jsdoc/0.js(61,19): error TS2339: Property 'a' does not exist on type 'String'.
2-
tests/cases/conformance/jsdoc/0.js(61,22): error TS2339: Property 'b' does not exist on type 'String'.
3-
tests/cases/conformance/jsdoc/0.js(63,20): error TS8024: JSDoc '@param' tag has name 'y', but there is no parameter with that name.
1+
tests/cases/conformance/jsdoc/0.js(68,19): error TS2339: Property 'a' does not exist on type 'String'.
2+
tests/cases/conformance/jsdoc/0.js(68,22): error TS2339: Property 'b' does not exist on type 'String'.
3+
tests/cases/conformance/jsdoc/0.js(70,20): error TS8024: JSDoc '@param' tag has name 'y', but there is no parameter with that name.
44

55

66
==== 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
5858
*/
5959
function good8({a, b}) {}
6060

61+
/**
62+
* @param {{ a: string }} argument
63+
*/
64+
function good9({ a }) {
65+
console.log(arguments, a);
66+
}
67+
6168
/**
6269
* @param {object} obj - this type gets ignored
6370
* @param {string} obj.a

tests/baselines/reference/jsdocParamTag2.symbols

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,40 @@ function good8({a, b}) {}
9393
>a : Symbol(a, Decl(0.js, 52, 16))
9494
>b : Symbol(b, Decl(0.js, 52, 18))
9595

96+
/**
97+
* @param {{ a: string }} argument
98+
*/
99+
function good9({ a }) {
100+
>good9 : Symbol(good9, Decl(0.js, 52, 25))
101+
>a : Symbol(a, Decl(0.js, 57, 16))
102+
103+
console.log(arguments, a);
104+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
105+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
106+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
107+
>arguments : Symbol(arguments)
108+
>a : Symbol(a, Decl(0.js, 57, 16))
109+
}
110+
96111
/**
97112
* @param {object} obj - this type gets ignored
98113
* @param {string} obj.a
99114
* @param {string} obj.b - and x's type gets used for both parameters
100115
* @param {string} x
101116
*/
102117
function bad1(x, {a, b}) {}
103-
>bad1 : Symbol(bad1, Decl(0.js, 52, 25))
104-
>x : Symbol(x, Decl(0.js, 60, 14))
105-
>a : Symbol(a, Decl(0.js, 60, 18))
106-
>b : Symbol(b, Decl(0.js, 60, 20))
118+
>bad1 : Symbol(bad1, Decl(0.js, 59, 1))
119+
>x : Symbol(x, Decl(0.js, 67, 14))
120+
>a : Symbol(a, Decl(0.js, 67, 18))
121+
>b : Symbol(b, Decl(0.js, 67, 20))
107122

108123
/**
109124
* @param {string} y - here, y's type gets ignored but obj's is fine
110125
* @param {{a: string, b: string}} obj
111126
*/
112127
function bad2(x, {a, b}) {}
113-
>bad2 : Symbol(bad2, Decl(0.js, 60, 27))
114-
>x : Symbol(x, Decl(0.js, 65, 14))
115-
>a : Symbol(a, Decl(0.js, 65, 18))
116-
>b : Symbol(b, Decl(0.js, 65, 20))
128+
>bad2 : Symbol(bad2, Decl(0.js, 67, 27))
129+
>x : Symbol(x, Decl(0.js, 72, 14))
130+
>a : Symbol(a, Decl(0.js, 72, 18))
131+
>b : Symbol(b, Decl(0.js, 72, 20))
117132

tests/baselines/reference/jsdocParamTag2.types

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ function good8({a, b}) {}
9393
>a : string
9494
>b : string
9595

96+
/**
97+
* @param {{ a: string }} argument
98+
*/
99+
function good9({ a }) {
100+
>good9 : ({ a }: { a: string;}, ...args: any[]) => void
101+
>a : string
102+
103+
console.log(arguments, a);
104+
>console.log(arguments, a) : void
105+
>console.log : (...data: any[]) => void
106+
>console : Console
107+
>log : (...data: any[]) => void
108+
>arguments : IArguments
109+
>a : string
110+
}
111+
96112
/**
97113
* @param {object} obj - this type gets ignored
98114
* @param {string} obj.a

tests/cases/conformance/jsdoc/jsdocParamTag2.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ function good7(x, {a, b}, y) {}
5757
*/
5858
function good8({a, b}) {}
5959

60+
/**
61+
* @param {{ a: string }} argument
62+
*/
63+
function good9({ a }) {
64+
console.log(arguments, a);
65+
}
66+
6067
/**
6168
* @param {object} obj - this type gets ignored
6269
* @param {string} obj.a

0 commit comments

Comments
 (0)