Skip to content

Commit 40ec839

Browse files
authored
Fixes JSDoc @type function with variable args is interpreted incorrectly (#44864)
* Fixes #44386 * Add test * Move test from fourslash to conformance
1 parent 0996bff commit 40ec839

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12290,7 +12290,7 @@ namespace ts {
1229012290

1229112291
// Record a new minimum argument count if this is not an optional parameter
1229212292
const isOptionalParameter = isOptionalJSDocPropertyLikeTag(param) ||
12293-
param.initializer || param.questionToken || param.dotDotDotToken ||
12293+
param.initializer || param.questionToken || isRestParameter(param) ||
1229412294
iife && parameters.length > iife.arguments.length && !type ||
1229512295
isJSDocOptionalParameter(param);
1229612296
if (!isOptionalParameter) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/a.js ===
2+
/**
3+
* @type {function(boolean, string, ...*):void}
4+
*/
5+
const foo = function (a, b, ...r) { };
6+
>foo : Symbol(foo, Decl(a.js, 3, 5))
7+
>a : Symbol(a, Decl(a.js, 3, 22))
8+
>b : Symbol(b, Decl(a.js, 3, 24))
9+
>r : Symbol(r, Decl(a.js, 3, 27))
10+
11+
=== tests/cases/conformance/jsdoc/b.ts ===
12+
foo(false, '');
13+
>foo : Symbol(foo, Decl(a.js, 3, 5))
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/jsdoc/a.js ===
2+
/**
3+
* @type {function(boolean, string, ...*):void}
4+
*/
5+
const foo = function (a, b, ...r) { };
6+
>foo : (arg0: boolean, arg1: string, ...arg2: any[]) => void
7+
>function (a, b, ...r) { } : (a: boolean, b: string, ...r: any[]) => void
8+
>a : boolean
9+
>b : string
10+
>r : any[]
11+
12+
=== tests/cases/conformance/jsdoc/b.ts ===
13+
foo(false, '');
14+
>foo(false, '') : void
15+
>foo : (arg0: boolean, arg1: string, ...arg2: any[]) => void
16+
>false : false
17+
>'' : ""
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @allowJS: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// @filename: a.js
6+
/**
7+
* @type {function(boolean, string, ...*):void}
8+
*/
9+
const foo = function (a, b, ...r) { };
10+
11+
// @filename: b.ts
12+
foo(false, '');

0 commit comments

Comments
 (0)