Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] Classify arrow functions as function kind in the doc model exports. #4513

Conversation

bartvandenende-wm
Copy link
Contributor

@bartvandenende-wm bartvandenende-wm commented Feb 6, 2024

Summary

Classify arrow functions as function kind in the doc model exports.

Related issue ticket #1629

Screenshot 2024-02-06 at 16 54 40

Details

The current behaviour of api-extractor is to classify arrow functions as variable kind. Even though syntactically correct, semantically (for documentation & usage purposes) this doesn't make any sense - and worse - it invalidates any documentation effort in the docstrings related to parameter descriptions, return types etc.

This PR modifies the doc-model generation to identify arrow functions in the variable declarations and processes them as function kinds instead.

Example code

/**
 * Demo log function
 * @param message - log message
 * @public
 */
export const log = (message: string): void => {console.log(message)}

doc model exports
Previous behaviour

{
  "kind": "Variable",
  "canonicalReference": "sample-lib!log:var",
  "docComment": "/**\n * Demo log function\n *\n * @param message - log message\n */\n",
  "excerptTokens": [
    {
      "kind": "Content",
      "text": "log: "
    },
    {
      "kind": "Content",
      "text": "(message: string) => void"
    }
  ],
  "fileUrlPath": "src/index.ts",
  "isReadonly": true,
  "releaseTag": "Public",
  "name": "log",
  "variableTypeTokenRange": {
    "startIndex": 1,
    "endIndex": 2
  }
}

New behaviour

  {
    "kind": "Function",
    "canonicalReference": "sample-lib!log:function(1)",
    "docComment": "/**\n * Demo log function\n *\n * @param message - log message\n */\n",
    "excerptTokens": [
      {
        "kind": "Content",
        "text": "log: (message: "
      },
      {
        "kind": "Content",
        "text": "string"
      },
      {
        "kind": "Content",
        "text": ") => "
      },
      {
        "kind": "Content",
        "text": "void"
      }
    ],
    "fileUrlPath": "src/index.ts",
    "returnTypeTokenRange": {
      "startIndex": 3,
      "endIndex": 4
    },
    "releaseTag": "Public",
    "overloadIndex": 1,
    "parameters": [
      {
        "parameterName": "message",
        "parameterTypeTokenRange": {
          "startIndex": 1,
          "endIndex": 2
        },
        "isOptional": false
      }
    ],
    "name": "log"
  }

How it was tested

manual testing

Impacted documentation

N/A

@iclanton iclanton merged commit c88b970 into microsoft:main Feb 6, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants