Where are the comment for functions located in typedoc?

83 views Asked by At

I'm working on the implementation of typedoc for my company's documentation. I've been working with TypeDoc without issues for months but I've been stuck on something for days now.

I'm trying to modify the comments for functions in my documentation. For other types its easy, i just grab the "comment.summary" element in the components i grab from the converter.EVENT_CREATE_DELCLARATION and modify them. However, for functions (kind 64), the "comment" attribute is empty, even if there is a comment displayed in the documentation.

name: 'addCalculatedMeasure',
  kind: 64,
  variant: 'declaration',
  conversionFlags: 0,
  comment: undefined,
  escapedName: 'addCalculatedMeasure',
  sources: [
    SourceReference {
      fileName: '/home/adamlr/Documents/atoti-ui/packages/mdx/dist/addCalculatedMeasure.d.ts',
      fullFileName: '/home/adamlr/Documents/atoti-ui/packages/mdx/dist/addCalculatedMeasure.d.ts',
      line: 7,
      character: 24
    }

For reference, this is how another type looks :

name: 'CellSetTable',
  kind: 64,
  variant: 'declaration',
  conversionFlags: 1,
  comment: Comment {
    blockTags: [],
    modifierTags: Set(0) {},
    summary: [ [Object] ]
  },
  escapedName: 'CellSetTable',
  sources: [
    SourceReference {
      fileName: '/home/adamlr/Documents/atoti-ui/packages/table/dist/cellset-table/CellSetTable.d.ts',
      fullFileName: '/home/adamlr/Documents/atoti-ui/packages/table/dist/cellset-table/CellSetTable.d.ts',
      line: 23,
      character: 21
    }
  ]

Any idea of where the comment for the first element might be hidden ? Thanks for your help.

(Using TypeDoc 0.24.7, Typescript 5.0.4)

1

There are 1 answers

0
Gerrit0 On

Comments for functions are unfortunately the most convoluted part of TypeDoc's models. In general, the comment you want will be on reflection.signatures[i].comment, but signatures are not created at the time EVENT_CREATE_DECLARATION is fired, so you will want to listen to Converter.EVENT_CREATE_SIGNATURE to pick up those comments.

Note: There may be a comment on the wrapping function declaration as well. If there is, this comment will be later copied to any signatures which do not have a comment.

/** comment on a signature */
function overloaded(): number
function overloaded(x: string): string
/** comment on the declaration, will be used for the string overload */
function overloaded(x?: string): string | number {
  return 1;
}