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

Improve behaviour of ... inside JSDoc functions #22809

Merged
merged 3 commits into from
Mar 22, 2018

Conversation

sandersn
Copy link
Member

  1. No error for ...type when it is the last parameter of a jsdoc function() type.
  2. ...type is marked as a rest parameter.
  3. ...type results in type[] inside a jsdoc function type.

Fixes #22508

@sandersn sandersn requested review from weswigham and a user March 22, 2018 21:18
// from bcryptjs
/** @param {function(...[*])} callback */
function g(callback) {
>g : (callback: (...arg0: [any][]) => any) => void
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the intention to have a single-element tuple type in an array?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it, given the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this came from some real (but quite confused) jsdoc in bcryptjs. I think the author's intent was any[][] but they wrote ...[*]

@@ -24542,6 +24549,11 @@ namespace ts {
}
}
}
if (isParameter(parent) && isJSDocFunctionType(parent.parent)) {
if (last(parent.parent.parameters) === parent) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this if is necessary, just use an array type all the time, we will issue a diagnostic for a non-last parameter anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess you're right. I'm not sure adding | undefined as the fallback case ever makes sense, actually.

@sandersn sandersn merged commit e16bb3e into master Mar 22, 2018
@sandersn sandersn deleted the js/jsdoc-variadic-in-jsdoc-function branch March 22, 2018 23:17
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants