Microsoft/TypeScript

Attach Documentation to Labeled Tuple Elements

Open

#49,998 创建于 2022年7月22日

在 GitHub 查看
 (2 评论) (2 反应) (0 负责人)TypeScript (6,726 fork)batch import
Experience EnhancementHelp WantedSuggestion

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

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.

贡献者指南