Skip to content

Standardize JSDoc for TypeScript function parameters #1128

@victorlin

Description

@victorlin

continuing conversation from #1124 (comment)

There are two approaches to add JSDoc descriptions for TypeScript function parameters.

  1. In the parameter type definition's JSDoc block. Example:

    export default async function parseMarkdown({
    mdString,
    addHeadingAnchors = false,
    headingAnchorClass = undefined,
    }: {
    mdString: string
    /** Should `<a>` tags be added to headings? */
    addHeadingAnchors?: boolean
    /** Class name for heading anchors (from page-specific CSS Module) */
    headingAnchorClass?: string
    }): Promise<string> {

    Benefits:

    • Description appears on hover of the parameter
    • Keeps the variable name, type, and description all in one place with no duplication
  2. In the function's JSDoc block using @param. Example:

    * @param versioned - boolean for whether the resources are versioned
    * @param elWidth - width of the element
    * @param quickLinks - list of `QuickLink` objects for the resources
    * @param defaultGroupLinks - boolean for if the group name is a url
    * @param groupDisplayNames - apping from group name -> display name
    * @param tileData - the tiles for the resources
    */
    function ListResourcesContent({

    Benefits:

    • Description appears on hover of the function

Tasks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions