Typedoc: Documenting destructured parameters

Created on 3 Dec 2017  路  7Comments  路  Source: TypeStrong/typedoc

I'm not entirely sure if this is a bug, enhancement, or just a misunderstanding on my part. How should I document this function?

Given the following source:

/**
 * @param b a string
 * @param c some number
 */
function dest({ a: b, b: { c } }: { a: string, b: { c: number } }): string {
  let out = '';
  for (let i = 0; i < c; i++) out += b
  return out
}

I would expect output similar to the following:

dest

dest(__namedParameters: object): string

Parameters

  • __namedParameters: object

    • a: string a string

    • b: object



      • c: number a number



Instead, this is generated

dest

dest(__namedParameters: object): string

Parameters

  • __namedParameters: object

    • b: object a string

    • c: number

The documentation for __namedParameters.a is dropped since the value is assigned to b and the application gets confused with the b property (I believe this is a rather obscure bug). A related, less obscure bug, is that if destructuring is used in two parameters, they will both be referred to as __namedParameters in the generated documentation.

bug

All 7 comments

This may be a duplicate of #522

I don't believe this is a duplicate, that issue seems to have been fixed as the first example works.

A simpler reproduction:

/**
 * @param b a string
 * @param c some number
 */
function dest({ a: b, b: c }: { a: string, b: number }): string {
}

I believe it would be better to document parameters based on the type definition rather than the assigned argument, that is, I believe it would be better to document this function like this:

/**
 * @param a a string
 * @param b some number
 */
function dest({ a: b, b: c }: { a: string, b: number }): string {
}

Or, reducing the potential for ambiguity (and following VSCode's autocomplete)

/**
 * @param param0.a a string
 * @param param0.b some number
 */
function dest({ a: b, b: c }: { a: string, b: number }): string {
}

I encountered similar issue. I suspect this is not a supported feature (not sure if there are any plans to support it).

So, as a workaround, I am going to avoid destructuring when declaring the function. Instead, just specify the object's name (i.e. input). On the first line of the function, do the same destructuring.

One extra line, much better looking docs - worth it. :-)

typedoc-destruc-param

@kctang I can't make it work as in your screen shots. Can you provide the doc comment on top of your function that works with your method?

I've discovered you can use normal object destructuring and get param comments if you do it like so:

export const useOAuth2Token = ({
  /**
   * efc
   */
  authorizeUrl,
  scope = [],
  redirectUri,
  clientID
}: {
  authorizeUrl: string
  scope: string[],
  redirectUri: string,
  clientID: string
}) => {

Which results in this:

image

This seems to be quite an old issue and still not addressed. Is Typedoc ever going to support destructured named parameters? The JSDoc approach could be a valid solution.

In TypeDoc 0.20, the original code renders as:

image

Which seems mostly reasonable to me (though I was somewhat surprised that "some number" was attached to c)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mirismaili picture mirismaili  路  3Comments

mcmath picture mcmath  路  3Comments

topherfangio picture topherfangio  路  3Comments

euberdeveloper picture euberdeveloper  路  3Comments

unsafecode picture unsafecode  路  4Comments