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

Props Table doesn't display for Props with complex types (Typescript addon-docs) #10087

Closed
shripadk opened this issue Mar 9, 2020 · 4 comments

Comments

@shripadk
Copy link

shripadk commented Mar 9, 2020

Describe the bug
This bug is specific to Typescript. When you import Props from another Component and create a union type with current Component's Props, the Props table fails to load.

Expected behavior
Expect Props Table to be displayed for Components with complex Props Types.

Screenshots
Screen Shot 2020-03-10 at 4 02 23 AM

Code snippets to Reproduce the above problem
An example Button Component (assume it is at ./src/Button.tsx):

import * as React from "react"

export type Props = {
  type: "button" | "submit" | "reset"
  kind?: string
  children: React.ReactNode
}

export function Button(props: Props) {
  return (
    <button className={props.kind} type={props.type}>
      {props.children}
    </button>
  )
}

A Submit Button Component (assume it is at ./src/SubmitButton.tsx):

import * as React from "react"
import { Button, Props as ButtonProps } from "./Button"

export type Props = ButtonProps & {
  color: string
}

export function SubmitButton(props: Props) {
  return (
    <Button type="submit">
      {props.children} <strong style={{ color: props.color }}></strong>
    </Button>
  )
}

Story for the above SubmitButton component (in MDX):

import { Meta, Story, Props, Preview } from '@storybook/addon-docs/blocks'
import { SubmitButton } from "../src/SubmitButton"

<Meta title="SubmitButton" component={SubmitButton} />

# SubmitButton

<Preview withToolbar>
  <Story name='Default'>
    <SubmitButton color="blue">Submit</SubmitButton>
  </Story>
</Preview>

### Props

<Props of={SubmitButton} />

System:

Environment Info:

  System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
  Binaries:
    Node: 10.18.1 - /usr/local/bin/node
    Yarn: 1.22.0 - ~/.yarn/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 80.0.3987.132
    Firefox: 67.0.4
    Safari: 13.0.5
  npmPackages:
    @storybook/addon-a11y: ^5.3.14 => 5.3.14 
    @storybook/addon-actions: ^5.3.14 => 5.3.14 
    @storybook/addon-docs: ^5.3.14 => 5.3.14 
    @storybook/addon-info: ^5.3.14 => 5.3.14 
    @storybook/addon-knobs: ^5.3.14 => 5.3.14 
    @storybook/addon-links: ^5.3.14 => 5.3.14 
    @storybook/addons: ^5.3.14 => 5.3.14 
    @storybook/react: ^5.3.14 => 5.3.14

Additional context
I tested it directly with react-docgen-typescript which I believe is what Storybook is using beneath the hood. It gives me the correct output. Have attached a screenshot of the same here:

Screen Shot 2020-03-10 at 3 55 49 AM

@shilman
Copy link
Member

shilman commented Mar 9, 2020

It looks like the loader is not running properly on your typescript files. Do you have a repro?

@shripadk
Copy link
Author

shripadk commented Mar 9, 2020

@shilman I can make one and put it up in sometime. The loader is working for simpler components. As soon as I create a complex Props type it fails.

shripadk added a commit to shripadk/storybook-repro that referenced this issue Mar 9, 2020
@shripadk
Copy link
Author

shripadk commented Mar 9, 2020

@shilman Have pushed a repro repo here: https://github.com/shripadk/storybook-repro

Two stories: one for Button component and another for SubmitButton. As you'll be able to see, the Button props table renders perfectly. SubmitButton on the other hand renders an empty props table.

Screenshot of Button Props Table:
Screen Shot 2020-03-10 at 5 09 41 AM

Screenshot of SubmitButton Props Table:
Screen Shot 2020-03-10 at 5 09 52 AM

@shilman
Copy link
Member

shilman commented Mar 10, 2020

Thanks @shripadk. This looks like a dupe to #9591, I'm going to close this for now.

@shilman shilman closed this as completed Mar 10, 2020
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

2 participants