JSDoc ...rest parameter syntax cannot support tuple types
See original GitHub issueBug Report
🔎 Search Terms
jsdoc rest tuple
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSDoc
⏯ Playground Link
Playground link with relevant code
💻 Code
/**
* @callback CBFunction
* @param {number} n
* @param {string} s
*/
// Desired outcome:
// typedef CBCaller = (...args: Parameters<CBFunction>) => void
/**
* @param {...Parameters<CBFunction>} args
*/
function f(...args) {
console.log(args);
}
🙁 Actual behavior
See Playground link: on .d.ts
tab, the output is declare function f(...args: [number, string][]): void;
, an array-of-tuples. Generally, JSDoc syntax treats {...X} args
as args: X[]
.
🙂 Expected behavior
TS-flavored JSDoc should be able to express any type that TS can express.
Issue Analytics
- State:
- Created a year ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
JSDoc Reference - TypeScript: Documentation
JSDoc Reference. The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.
Read more >Joshua's Docs - JSDoc Cheatsheet and Type Safety Tricks
VSCode now supports Tuple types expressed through JSDoc, in a variety of different ways. Standard Tuple Type: /** @typedef {[string, number]} ...
Read more >Typescript: What is the point of using a tuple as a rest ...
The rest tuple syntax lets you abstract over function parameter lists in a way that a regular call signature does not.
Read more >Overview - TypeScript
We can prefix any tuple type with the readonly keyword to make it a readonly ... The declarations use generic rest parameters (see...
Read more >August 2020 - TypeScript - Microsoft Developer Blogs
To deepen the connection between parameter lists and tuple types, the syntax for rest elements and optional elements mirrors the syntax for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
TS’ jsdoc doesn’t currently have a good way to match any rest parameter to a
@param
tag. The code you wrote is unfortunately already used by closure type syntax in jsdoc, so thisIs like writing this:
even if it weren’t used, everything inside
{}
is supposed to be a type.We need an alternate proposal. One possibility is to add the … on the parameter name:
This might conflict with existing jsdoc, but I don’t think it does off the top of my head. And I think it would be possible to enforce the usual rules on
...
: eg that it can only occur once, at the end of a parameter list.tsd-jsdoc
does not currently use the TS compiler, though they have been thinking about it for a while. I believe the answer to your question is, they only support a subset of all the JSDoc constructs that the TS compiler does.