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

info addon: TypeScript/React PropTypes: "No propTypes defined!" #5073

Closed
mweibel opened this issue Dec 21, 2018 · 3 comments
Closed

info addon: TypeScript/React PropTypes: "No propTypes defined!" #5073

mweibel opened this issue Dec 21, 2018 · 3 comments

Comments

@mweibel
Copy link

mweibel commented Dec 21, 2018

When using TypeScript, React, and styled components the info addon doesn't seem to be able to show propTypes for the components.

To Reproduce
A minimal reproducing example is found here:

https://github.com/mweibel/storybook-typescript-example

You can start storybook with npm start.

Expected behavior
Available propTypes are being shown.

Screenshots
screenshot 2018-12-21 at 07 25 35

System:

  • OS: macOS
  • Device: MacBook Prop
  • Browser: Firefox
  • Framework: react
  • Addons: actions, info, knobs
  • Version: 4.1.3 but also happens with 4.0.12 (and possibly lower, didn't check those)
@leroykorterink
Copy link

The properties table is created in makeTableComponent.js:80, this function is trying to get the proptype definition from type.propTypes or type.__docgenInfo.

You're usually not setting static propTypes properties on your React component when you're also using typescript. This means that you should use a documentation generator to create the type.__docgenInfo property for your components.

You're using a different documentation generator in your webpack.config.js than the one used in the typescript configuration example. Try using the documentation generator from the example, that one works fine for me.

@mweibel
Copy link
Author

mweibel commented Jan 3, 2019

You're right! Using the docgen typescript loader instead of the plugin solved the issue for me.

FTR:

diff --git a/config/storybook/webpack.config.js b/config/storybook/webpack.config.js
index 7b09508..f048270 100644
--- a/config/storybook/webpack.config.js
+++ b/config/storybook/webpack.config.js
@@ -1,5 +1,4 @@
 const path = require("path");
-const TSDocgenPlugin = require("react-docgen-typescript-webpack-plugin");

 module.exports = (baseConfig, env, config) => {
   config.module.rules.push({
@@ -7,10 +6,12 @@ module.exports = (baseConfig, env, config) => {
     use: [
       {
         loader: "ts-loader"
+      },
+      {
+        loader: "react-docgen-typescript-loader"
       }
     ]
   });
-  config.plugins.push(new TSDocgenPlugin());
   config.resolve.extensions.push(".ts", ".tsx");
   return config;
 };

Thanks!

@mweibel mweibel closed this as completed Jan 3, 2019
@adyz
Copy link

adyz commented Sep 13, 2019

Also, if you are using React with Typescript and use this:

export default class MyComponent {}

instead of:

class MyComponent {}
export default MyComponent

it will not show the prop types

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

4 participants