Skip to content

Attach Documentation to Labeled Tuple Elements #49998

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

Open
5 tasks done
harrysolovay opened this issue Jul 22, 2022 · 2 comments
Open
5 tasks done

Attach Documentation to Labeled Tuple Elements #49998

harrysolovay opened this issue Jul 22, 2022 · 2 comments
Labels
Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@harrysolovay
Copy link

Suggestion

I often find myself describing function params as labeled tuples. A simple example:

type AddArgs = [a: number, b: number];
function add(...[a, b]: AddArgs): number {
  return a + b;
}

Unfortunately, this approach prevents us from attaching tsdocs to the params. The following does not work :/

type AddArgs = [a: number, b: number];
/**
 * @param a the first number
 * @param b the second number
 */
function add(...[a, b]: AddArgs): number {
  return a + b;
}

I propose that one be able to attach tsdocs to labeled tuple elements, just as one does to object keys.

type AddArgs = [
  /** the first number */
  a: number,
  /** the second number */
  b: number,
];

I also propose that––when spread in place of function params––these tsdocs are treated as if they were the result of @param annotations on the function declaration.

🔍 Search Terms

Documentation, labeled, tuple, elements, tsdocs, signature

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@harrysolovay
Copy link
Author

Linking to #41165 for posterity

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Experience Enhancement Noncontroversial enhancements labels Jul 28, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 28, 2022
@sirius16
Copy link

sirius16 commented Oct 5, 2023

I hope this gets done, it would be very helpful in writing overload functions were vargs/args would be a union of labeled tuples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants