Closed MariaTeo closed 6 months ago
@MariaTeo thank you for testing Storybook 8-alpha! I am not able to reproduce your issue in a fresh Next.js project. Could you share a reproduction of your issue with storybook.new? That will help us significantly in the debugging process. Thank you!
hello @vanessayuenn thank you for your response. I have reproduced the issue here. Hope that helps
I've put up another repro of this behavior here.
// variants.ts
export const variants = {
sizes: {
small: 'text-sm',
medium: 'text-base',
large: 'text-lg',
},
};
// Button.tsx
type SizeOptions = keyof typeof variants['sizes'];
interface ButtonProps {
// ...
/**
* How large should the button be?
*/
size?: SizeOptions;
In the description for size
, it says
How large should the button be?
unknown
Storybook 7 handles this correctly:
How large should the button be?
small
medium
large
I've experimented and it only says unknown
if the type of the prop has to use the bracket syntax (keyof typeof variants['sizes']
. If I can write keyof typeof sizes
, then it says union
, which isn't much better.
const sizes = {
small: 'text-sm',
medium: 'text-base',
large: 'text-lg',
};
export const variants = { sizes };
type SizeOptions = keyof typeof sizes;
How large should the button be?
union
This is also what you get if you put a union type directly in the prop:
interface ButtonProps {
//...
intent?: 'secondary' | 'primary';
}
How large should the button be?
union
Again, Storybook 7 handles both of these cases correctly, listing the actual options instead of returning union
.
@HerbCaudill I've verified that setting typescript.reactDocgen
to react-docgen-typescript
restores the old behavior: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-docgen-component-analysis-by-default
@MariaTeo I think the PR attached closes your issue. Thank you for supplying the reproduction, it was very useful in tracking down the problem.
Considering you're overriding argTypes manually, you might find that you'll sometimes need to manually specify the type
property too:
...
argTypes: {
as: {
type: 'string',
description:
'Represents what kind of header should the text be, by default it is rendered as a paragraph',
control: 'select',
options: ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
defaultValue: 'p',
property: 'string',
},
...
And you can supply something more complex using table
:
(This code already works without the patch)
This is happening in a nextjs14 project with typescript.
this is part of my package.json
My config seems to be fine. Types of props are not being defined in the storybook docs
To Reproduce
No response
System
No response
Additional context
No response