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

support function type documentation #23

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

souporserious
Copy link
Owner

Adds support for function type documentation in getTypeDocumentation by parsing properties that are FunctionType. This can be the case for several reasons, but came up when documenting child functions in React:

import * as React from 'react';

function getExportedTypes() {
  return [
    { 
      /** The name of the component. */ 
      name: 'Button',

      /** The description of the component. */
      description: 'A button component' 
    }
  ]
}

type ExportedTypesProps = {
  /** Controls how types are rendered. */
  children?: (
    exportedTypes: ReturnType<typeof getExportedTypes>
  ) => React.ReactNode
}

function ExportedTypes({ children }: ExportedTypesProps) {}

Is now parsed as:

{
  "name": "ExportedTypes",
  "parameters": [
    {
      "properties": [
        {
          "description": "Controls how types are rendered.",
          "name": "children",
          "parameters": [
            {
              "name": "exportedTypes",
              "type": "{ name: string; description: string; }[]",
            },
          ],
          "required": false,
          "returnType": "React.ReactNode",
          "type": "(exportedTypes: ReturnType<typeof getExportedTypes>) => React.ReactNode",
        },
      ],
      "required": true,
      "type": "ExportedTypesProps",
   }
 ]
}

This will still include unrelated fields like defaultValues, required etc since this is utilizing the same utility to unwrap normal function arguments. An additional function type arguments utility can be handled in a follow-up.

Copy link

vercel bot commented Jun 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsxmod ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 6:56pm

Copy link

changeset-bot bot commented Jun 17, 2024

🦋 Changeset detected

Latest commit: 6f01c3e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tsxmod/utils Minor
tsxmod Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@souporserious souporserious merged commit d60c091 into main Jun 17, 2024
3 checks passed
@souporserious souporserious deleted the function-type-documentation branch June 17, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant