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

Nested type descriptions #683

Open
neutraali opened this issue Nov 18, 2022 · 3 comments
Open

Nested type descriptions #683

neutraali opened this issue Nov 18, 2022 · 3 comments

Comments

@neutraali
Copy link

neutraali commented Nov 18, 2022

Sorry if this has been reported before in some form before, but is there currently support for nested type descriptions? For example, given the following structure (using Flow and react-docgen@5.3.1):

type Panel = {
	/** Panel title */
	title: string,
	/** Panel content */
	content: string,
	/** Sublevels of more Panels */
	panels: Array<Panel>
};

type Props = {
	/** One or more toggleable Panels */
	panels: Array<Panel>
}

/** Hello World! */
const Component = (props: Props) => { ... }

^ Does not generate any description for the Panel -props. Is this intentional? The output for a Panel is:

{
	"name": "signature",
	"type": "object",
	"raw": "{ ... }",
	"signature": {
		"properties": [
			{
				"key": "title",
				"value": {
					"name": "string",
					"required": true
				}
			},
			{
				"key": "content",
				"value": {
					"name": "string",
					"required": true
				}
			},
			{
				"key": "panels",
				"value": {
					"name": "Array",
					"elements": [{ "name": "Panel" }],
					"raw": "Array<Panel>",
					"required": true
				}
			}
		]
	}
}
@danez danez added the lib label Apr 15, 2023
@kevin-krug
Copy link

kevin-krug commented May 22, 2023

just would like to add my +1 here, in typescript nested interfaces seem to not be resolved currently.

if this is not already supported, I'd request for the output of the parse function to include the nested props, also in case of nested interfaces. 🙏

E.g. both below cases should yield the same output:

case 1. without nested interface

interface Props {
  prop: {
    nestedProp: string
  }
}

const Component = (prop: Props) => {
  return <div />;
}

current output (expected output also for case 2.)
=>

[
  {
    "description": "",
    "displayName": "Component",
    "methods": [],
    "props": {
      "prop": {
        "required": true,
        "tsType": {
          "name": "signature",
          "type": "object",
          "raw": "{\n  nestedProp: string\n}",
          "signature": {
            "properties": [
              {
                "key": "nestedProp",
                "value": {
                  "name": "string",
                  "required": true
                }
              }
            ]
          }
        },
        "description": ""
      }
    }
  }
]

VS.

case 2. with nested interface

interface Props {
  prop: NestedProp
}

interface NestedProp {
  nestedProp: string
}

const Component = (prop: Props) => {
  return <div />;
}

=>

[
  {
    "description": "",
    "displayName": "Component",
    "methods": [],
    "props": {
      "prop": {
        "required": true,
        "tsType": {
          "name": "NestedProp"
        },
        "description": ""
      }
    }
  }
]

@danez
Copy link
Collaborator

danez commented Jun 23, 2023

just would like to add my +1 here, in typescript nested interfaces seem to not be resolved currently.

if this is not already supported, I'd request for the output of the parse function to include the nested props, also in case of nested interfaces. 🙏

When TypeScript support was implemented there was the decision made to handle interfaces different than object types and type aliases. The reason was that interfaces might be documented separately and linked from the component docs. I can see that use case but also think that the same could apply for object types or enums. So it might be nice to find a way to allow this will still documenting everything.

What I'm thinking of is to handle interfaces and object types exactly the same, except to somehow make it clear that it is an interface. In addition it might be interesting to add a referenceName, so that in the end the name of the interface/typealias is still known.

Maybe something like this for your example above. Would that work for you?

"tsType": {
          "name": "signature",
          "referenceName" : "NestedProp", 
          "type": "interface",
          ...
}

@danez
Copy link
Collaborator

danez commented Jun 23, 2023

Sorry if this has been reported before in some form before, but is there currently support for nested type descriptions? For example, given the following structure (using Flow and react-docgen@5.3.1):

type Panel = {
	/** Panel title */
	title: string,
	/** Panel content */
	content: string,
	/** Sublevels of more Panels */
	panels: Array<Panel>
};

type Props = {
	/** One or more toggleable Panels */
	panels: Array<Panel>
}

/** Hello World! */
const Component = (props: Props) => { ... }

^ Does not generate any description for the Panel -props. Is this intentional? The output for a Panel is:

{
	"name": "signature",
	"type": "object",
	"raw": "{ ... }",
	"signature": {
		"properties": [
			{
				"key": "title",
				"value": {
					"name": "string",
					"required": true
				}
			},
			{
				"key": "content",
				"value": {
					"name": "string",
					"required": true
				}
			},
			{
				"key": "panels",
				"value": {
					"name": "Array",
					"elements": [{ "name": "Panel" }],
					"raw": "Array<Panel>",
					"required": true
				}
			}
		]
	}
}

This issue with flow and missing descriptions will be fixed in the next release. see #810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants