Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDoc rest arguments can no longer be extracted with Parameters<T> #43072

Closed
Gerrit0 opened this issue Mar 4, 2021 · 1 comment · Fixed by #43562
Closed

JSDoc rest arguments can no longer be extracted with Parameters<T> #43072

Gerrit0 opened this issue Mar 4, 2021 · 1 comment · Fixed by #43562
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@Gerrit0
Copy link
Contributor

Gerrit0 commented Mar 4, 2021

Bug Report

According to the docs, {...string} can be used to define a rest parameter having type string[]. This works for the implementation, but does not construct a type that can be extracted using standard utility types.

🔎 Search Terms

JSDoc variadic arguments, var args, rest arguments

🕗 Version & Regression Information

This was discovered while upgrading TypeScript from 4.1.5 to 4.2.2 in TypeDoc. There is a test case for variadic parameters which changed in an unexpected way.

Please keep and fill in the line that best applies:

  • This changed between versions 4.1.5 and 4.2.2

⏯ Playground Link

Bug Workbench links:

💻 Code

// @filename: a.js

/**
 * @callback Foo
 * @param {...string} args
 * @returns {number}
 */

/** @type {Foo} */
export const x = () => 1

// @filename: b.ts
export {}

type Params = Parameters<typeof import("./a")['x']>
//   ^?

🙁 Actual behavior

TS 4.2 resolves Params = never

type Params = Parameters<typeof import("./a")['x']>
//   ^? - type Params = never

🙂 Expected behavior

TS 4.1 resolves Params = string[]

type Params = Parameters<typeof import("./a")['x']>
//   ^? - type Params = string[]
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 9, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.1 milestone Mar 9, 2021
@sandersn
Copy link
Member

sandersn commented Apr 6, 2021

The problem is with the interaction of @callback and @type; you can't even call x inside a.js like you'd expect: x('a', 'b'). Here's a smaller repro:

/**
 * @callback Foo
 * @param {...string} args
 * @returns {number}
 */

/** @type {Foo} */
export const x = () => 1
var res = x('a', 'b')

Note that changing x's definition to (...args) => 1 doesn't help.

Edit: however, switching to a TS annotation (which works fine in JS files) works.
Another interesting note: quickinfo gives the correct type for args when hovering x, but not 'a'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants