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

[Bug]: Documentation is not generated when using React.FC in TypeScript #21898

Closed
kyletsang opened this issue Apr 4, 2023 · 4 comments · Fixed by #22024
Closed

[Bug]: Documentation is not generated when using React.FC in TypeScript #21898

kyletsang opened this issue Apr 4, 2023 · 4 comments · Fixed by #22024

Comments

@kyletsang
Copy link
Contributor

kyletsang commented Apr 4, 2023

Describe the bug

When using React.FC to specify the component type, the documentation will not be generated.

Here is minimal repro of a component:

export interface AppProps {
  /**
   * A string paramter.
   */
  param1: string

  /**
   * A number parameter.
   */
  param2: number
}

/**
 * This is a component.
 */
const App: React.FC<AppProps> = ({ param1, param2 }) => {
  return (
    <div>
      <div>Param 1: {param1}</div>
      <div>Param 2: {param2}</div>
    </div>
  )
}

export default App

If I use the above snippet and substitute the declaration using the following, it works properly

const App = ({ param1, param2 }: AppProps) => {

This used to work in the earlier betas (Beta 33 I think?), but stopped working at some point after that. When I get a chance, I'll try to find the earliest version in which this started occurring.

To Reproduce

https://github.com/kyletsang/storybook-ts-docs-repro

System

Environment Info:

  System:
    OS: macOS 13.2.1
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 8.19.4
  Browsers:
    Chrome: 111.0.5563.146
    Edge: 111.0.1661.62
    Firefox: 109.0.1
    Safari: 16.3

Additional context

No response

@nuxcodes
Copy link

nuxcodes commented Apr 4, 2023

Similar to #21801. React.forwardRef also breaks ArgTypes type inference.

The type inference works once I remove React.FC, and the control becomes radio buttons for union types. But if the union type includes both null and undefined, the control would remain text controls.

image

@kasperpeulen
Copy link
Contributor

Somehow using a named export fixes this issue.
Even though that the component is still imported as a default export...
cc @shilman

image

@shilman
Copy link
Member

shilman commented Apr 11, 2023

Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.1 containing PR #22024 that references this issue. Upgrade today to the @future NPM tag to try it out!

npx sb@next upgrade --tag future

@shilman
Copy link
Member

shilman commented Apr 12, 2023

Yay!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.3 containing PR #22024 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb@latest upgrade

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

Successfully merging a pull request may close this issue.

4 participants