-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
TypeScript Props table limitations (MDX) <Props of={Component}/> #8143
Comments
forwardRef is a dupe to #7933, will treat that separately. The rest are super interesting, and I hope to dig in soon. |
I'm also not getting any details for my props. Im seeing the prop name, but not type or default, even though it is defined in the component. Im using CSF, but project is gatsby so using manual install with webapck config, not the preset. Very open for it being my own config causing this, Im no webpack pro. Components are functional so no React.Component options like described above. Was struggling with other issues, they should be fixed now, heres a repo: https://github.com/netliferesearch/netlife2019/tree/storybook_setup_stories |
FYI, @mrmckeb has done some awesome detective work that's possibly related to this. The TLDR is that there may be two problems:
tsDocgenLoaderOptions: {
tsconfigPath: path.resolve(__dirname, '../tsconfig.json'),
},
// The Babel plugin for docgen conflicts with the TypeScript loader.
// This limits it to JavaScript files when the TypeScript loader is enabled.
if (options.tsDocgenLoaderOptions) {
plugins = _plugins.filter(
([plugin]) => !plugin.includes('babel-plugin-react-docgen')
);
overrides = [
{
test: /\.(js|jsx)$/,
plugins: _plugins.filter(([plugin]) =>
plugin.includes('babel-plugin-react-docgen')
),
},
]; These changes have improved the docgen support in the CRA preset's typescript docgen settings: https://github.com/storybookjs/presets/pull/44/files I'm not sure how to operationalize them for more general configuration yet, but wanted to record that here in case anybody wants to experiment in their own setups! |
@shilman I'm not using typescript and still not seeing prop types and defaults. Should I file a separate bug? |
@kfayelun Yeah, I think that's a separate issue (though it may end up being the same underlying problem). Thanks! |
We do know that the TS and JS loaders/plugins can interfere with each other. A good base test is to ensure that you don't have both in the mix ;) |
Insight for point 1, 2, and 4: For us, it turned out that this is caused by how we extend Component: If we do We were even able to use
🤔 The error with |
@jonathanherdt ❤️ ❤️ ❤️ Thanks for tracking this down. Super helpful! Re: forwardRef, there's a PR in progress #8445 |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Generics issue (2) repro: e3927d9 I believe this is the corresponding |
Type import issue (3) repro: 4129773 Possibly fixed in reactjs/react-docgen#352 |
We've just released zero-config typescript support in 6.0-beta. Please upgrade and test it! Thanks for your help and support getting this stable for release! |
This seems to be due to a limitation of Storybook that by default it only runs type extraction on the user's project. So I think what's happening is:
The argType extractor sees this code and tries to find the types for As a workaround, you can try setting the following option in module.exports = {
typescript: {
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
},
},
}; This removes the default
More info: https://storybook.js.org/docs/react/configure/typescript This probably needs documentation @jonniebigodes |
@shilman, that works, although argTypes is not an optional parameter now. Thanks! import React from 'react';
import {Story} from '@storybook/react/types-6-0';
import AntButton from 'antd/lib/button';
export const argTypes = {
href: {
description: 'Ссылка, куда будет выполняться перенаправление',
table: {
type: {
summary: 'string'
}
},
control: {
type: 'text'
}
}
};
export const ButtonDefaultTemplate = ({...props}) => {
return <Button {...props}>Кнопка</Button>;
};
export const ButtonDefaultStory = ButtonDefaultTemplate.bind({});
ButtonDefaultStory.storyName = 'Базовый тип';
<Meta title="Button" component={Button} argTypes={argTypes} />
<Preview>
<Story name="Button">
{ButtonDefaultStory}
</Story>
</Preview>
<ArgsTable of={Button} /> How to hide all inherited properties and show controls instead? |
As a workaround, it's possible to create a custom table (but without controls): import React, {ComponentProps, FunctionComponent} from 'react';
import {Table, Typography} from 'antd';
type TableProps = {
name: string;
dataSource: ComponentProps<typeof Table>['dataSource'];
};
const render = (html: string): JSX.Element => {
return <div dangerouslySetInnerHTML={{__html: html}} />;
}
const CustomArgsTable: FunctionComponent<TableProps> = ({name, dataSource}): JSX.Element => (
<div>
<Typography.Title level={3}>{name}</Typography.Title>
<Table dataSource={dataSource}
columns={[
{
title: 'Property',
dataIndex: 'property',
key: 'property'
},
{
title: 'Description',
dataIndex: 'description',
key: 'description',
render
},
{
title: 'Type',
dataIndex: 'type',
key: 'type',
render
},
{
title: 'Value',
dataIndex: 'value',
key: 'value'
}
]}
bordered={true}
pagination={{hideOnSinglePage: true}}
/>
</div>
);
export {CustomArgsTable}; import React from 'react';
import {Story} from '@storybook/react/types-6-0';
import {Button} from './button';
import {ButtonDefaultStory , argTypes} from './button.stories.tsx';
import {CustomArgsTable} from './utils.tsx';
export const dataSource = [
{
key: '1',
property: 'dropdownProps',
description: 'Props',
type: 'Dropdown',
value: '-'
},
<Meta title="Button" component={Button} argTypes={argTypes} />
<Preview>
<Story name="Button">
{ButtonDefaultStory}
</Story>
</Preview>
<CustomArgsTable name="Button" dataSource={dataSource} /> |
I'm not sure if this also the case stories written in CSF.
I've noticed a couple of limitations when trying to auto generating prop tables in typescript.
1. It looks like only Interfaces are supported, using a Type seems to break it.
2. using generics (in the case of react) seem to break it too, example below:
This works:
This doesn't
3. Using imported types like the example below are always inferred as
any
4. Doesnt work with React.forwardRef
The text was updated successfully, but these errors were encountered: