storybook: Some props not found Typescript
Describe the bug Some component’s props are not showed in the stories, i though it was just if i have union as props but it also work with some standard props interfaces
To Reproduce Steps to reproduce the behavior: Install storybook 5.2 and ‘@storybook/addon-storysource/loader’ Expected behavior See the props
Screenshots If applicable, add screenshots to help explain your problem.
Code snippets i have this simple component :
const SimpleCheckbox = (props: CheckBoxProps & { labelSize?: 'normal' | 'small' }) => { const [checked, setChecked] = useState(false); return <Checkbox label="Choice" checked={checked} onChange={() => setChecked(!checked)} {...props} />; };
and here’s my story
storiesOf('Checkbox', module) .addParameters({component: SimpleCheckbox}).....
and i don’t get any prop on my doc.
I have installed react-docgen-typescript-loader
and here’s my webpack config inside .storybook
const path = require('path');
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
module.exports = ({ config }) => {
// Only way to override webpack mode inside build-storybook
if (process.env.NODE_ENV === 'development') {
config.mode = process.env.NODE_ENV;
}
const rules = config.module.rules;
rules.push({
test: /\.(stories|story)\.mdx$/,
use: [
{
loader: 'babel-loader',
},
{
loader: '@mdx-js/loader',
options: {
compilers: [createCompiler({})],
},
},
],
});
rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('babel-loader'),
},
],
});
rules.push({
test: /\.tsx?$/,
include: path.resolve(__dirname, '../src'),
use: [
{
loader: require.resolve('ts-loader'),
}, {
loader: require.resolve('react-docgen-typescript-loader'),
},
],
});
rules.push({
test: /\.mdx$/,
use: [
'babel-loader',
'@mdx-js/loader',
],
});
rules.push({
test: /\.stories\.tsx?$/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: { parser: 'typescript' },
},
],
enforce: 'pre',
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
};
System: Environment Info:
System: OS: macOS 10.14.6 CPU: (4) x64 Intel® Core™ i5-7360U CPU @ 2.30GHz Binaries: Node: 10.16.3 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm Browsers: Chrome: 77.0.3865.75 Safari: 12.1.2 npmPackages: @storybook/addon-docs: ^5.3.0-alpha.0 => 5.3.0-alpha.0 @storybook/addon-info: ^5.2.1 => 5.2.1 @storybook/addon-storyshots: ^5.2.1 => 5.2.1 @storybook/addon-storysource: ^5.2.1 => 5.2.1 @storybook/addon-viewport: ^5.2.1 => 5.2.1 @storybook/react: ^5.2.1 => 5.2.1
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 19 (6 by maintainers)
@shilman Hmm… I have repeated steps in your gist. Everything works fine, except for default exports. If there are no named exports, default exports don’t work.
Story
Component.
This one doesn’t work.
But this works fine
Note an
exportstatement near the Button.Screenshots:
No named export
With named export
~Not to hijack this issue, but I’m having difficulty getting any props recognized in my project with Typescript. I’m just adding docs in https://github.com/gymnasium/gym-ui/pull/62 now. The typescript preset caused all kinds of problems in my project, so I modified the webpack config, but to no avail.~
~Right now the only
componentI have wired up isButton, but it’s not finding any props: https://deploy-preview-62--gymnasium-storybook.netlify.com/?path=/docs/button--default~~I followed the recommendation in the docs here to set up typescript~
~Would love any insights you might be able to offer!~
edit: update - I was modifying the wrong webpack config in my project. 🤦♂ Everything seems good now. My
.storybook/webpack.config.js:I’m not seeing any prop tables on the DocsPage either with a similar config. Using CRA and typescript, also swapped out babel-loader for ts-loader as specified in the typescript preset, but to no avail, it loaded, but still no prop tables.
@shilman Yes, no props shown there
@F-Moody just to clarify: this is about the props table in addon-docs?
@joanrm20 thanks for that! also, for anybody reading this, you might try the recommended 6.0 setup (should work in 5.3 too) and I expect that also to fix the problem:
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-prop-tables-with-typescript
@ElForastero I wrote a short walkthrough of how to set it up. Can you go through and see whether your setup matches. I’ve confirmed that this works:
https://gist.github.com/shilman/bc9cbedb2a7efb5ec6710337cbd20c0c
I’ve documented TS presets here: https://github.com/storybookjs/storybook/pull/8649
Any feedback on the changes is appreciated, since I’m still trying to get to the bottom of all this.
If you switch over to using presets, please let me know if:
Also, whether or not you’re using presets, please let me know if you see any opportunities to improve the docs here.
Many thanks!!!
@F-Moody @zzwong @ddaniel-dt @rickdunkin @sami616 @jonathanherdt @NateRadebaugh @ElForastero @mbifulco @alexwhin @bigmoves @coreybruyere @PilotConway @stale
@ElForastero In CRA, use
@storybook/preset-create-react-appfor TS support. We need to document this better… 😭I use ‘@storybook/preset-typescript’ with CRA and styled-components. And I see no props table neither with
typenorinterface.And there’s a strange hooks message instead of props table. This is probably some styled-components hook because I don’t have any in my Button component.
The only table I can get is regular Button.propTypes on a regular React.FC component (not styled-components). Without any TypeScript integration.