forwardRef trips up docgen #76
Description
Describe the bug
When implementing a Component in the way described below, the Storybook Props block (created via react-docgen-typescript-loader
) only shows the following text:
"Cannot read property 'appearance' of undefined"
To Reproduce
Declare a component in way mentioned under "Code snippets".
Expected behavior
The Props block should display the corresponding Props.
Code snippets
Button.tsx
type ButtonProps = {
appearance?: "primary" | "secondary" | "ghost";
} & JSX.IntrinsicElements["button"];
const Button: RefForwardingComponent<HTMLButtonElement, ButtonProps> = React.forwardRef(({ appearance, ...otherProps}, ref) => (
<button>...</button>
))
Button.displayName = "Button";
Button.defaultProps = {
appearance: "primary"
};
Button.stories.tsx
import React from "react";
import { storiesOf } from "@storybook/react";
import { Button } from "./Button";
storiesOf("Button", module)
.addParameters({
component: Button
})
.add("primary", () => (
<Button appearance="primary">
My primary button!
</Button>
))
;
System:
package.json
"react-docgen-typescript-loader": "^3.3.0"
Update: Also tested with 3.6.0.
Tried out with both Storybook 5.2.5 and Storybook 5.3.0-beta.1
Using stories in the TSX file format but encountered the error also when using the JSX file format.
Component is in TSX format.
Please paste the results of npx -p @storybook/cli@next sb info
here.
System:
OS: macOS 10.15.1
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Binaries:
Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
Browsers:
Chrome: 78.0.3904.97
Safari: 13.0.3
npmPackages:
@storybook/cli: ^5.3.0-beta.1 => 5.3.0-beta.1
Additional context
Used to work before introducing RefForwardingComponent
and React.forwardRef