microsoft / microsoft/tsdoc

RFC: less redundant syntax

Open
#286 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5k
Forks
162
Avg merge
17h 24m
Merged PRs (30d)
8

Description

Hello!

First and foremost, thanks for developing this tool — looks very promising.

Proposal

When documenting my TypeScript code, I generally try to avoid redundantly retyping variable names wherever possible. For example:

// Case 1
type Input = {
  /** Description of `n` goes here */
  n: number
}

/** Description of function goes here */
export const fn = ({ n }: Input) => {
  return n ^ 2
}

// Case 2
/** Description of function goes here */
export const fn = (
  /** Description of `n` goes here */
  n: number
) => {
  return n ^ 2
}

The Description of n goes here does not currently seem to be retrieved by tsdoc. Is this something that you would consider putting on the roadmap?

I see several upsides:

  • The parameter description is colocated with its name and type for easier visual grepping
  • It is not needed to retype the variable name anymore, avoiding potential mismatch when refactoring
  • @param can be left out, so less verbose (but equally clear) syntax
  • Works especially well (is visually pleasing) for functions with a destructured object as argument, cf. Case 1 above

Main downside:

  • Function declaration with non-destructured argument(s) (cf. Case 2 above) gets a bit more clumsy for large comment blocks, which may look unfamiliar. Therefore I would propose to keep this as an optional (and perhaps recommended) extension to the current way of working, and not as a replacement.

Reference

React Styleguidist allows for a similar syntax with propTypes.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or entry points are named. Start with the proposal's TypeScript examples and the React Styleguidist reference; done would mean deciding whether colocated parameter comments belong on the TSDoc roadmap and documenting the resulting direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.