You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is an issue with discriminated unions in TypeScript, but there's a variant of that in this project.
The Issue
Something's up with StoryObj types after upgrading to Storybook v8. It's saying all arg types are Partial<MyComponent> no matter what. The type itself has infer, but that's inferring the wrong type for some reason.
Before (v7)
Heavily simplified:
conststorybookMeta: Meta<MyComponentProps>={title: "MyComponent",component: MyComponent,args: {// my default args},};exportdefaultstorybookMeta;exportconstActionButton: StoryObj<MyComponentProps>={// Also doesn't work passing `typeof MyComponent` as a generic.args: {actionLabel: "Open app settings",},render: functionC(args){return(<MyComponent// TypeScript errors in v8 because `Partial<MyComponentProps>` isn't valid for `MyComponentProps`. That means `actionLabel` is now `string | undefined`. It doesn't care that `ActionButton.args.actionLabel` is a string. It's also not aware of any default values in the `Meta` type definition.{...args}/>)},};
After going through the reproduction, I noticed this project has the generics passed incorrectly. I changed them to match the TypeScript reproduction, but it didn't fix it.
Looking further, it appears to be an issue with optional props (discriminated unions) where in one case they're required, in another case they're optional and never.
I modified the Button and its stories in the reproduction:
exportconstPrimary: Story={args: {primary: true,label: 'Button',actionLabel: "yo"},render: (args)=>{args.actionLabel// This should be of type `string`, but it's `string | undefined`.return<Button{...args}/>}};
Describe the bug
I think this is an issue with discriminated unions in TypeScript, but there's a variant of that in this project.
The Issue
Something's up with
StoryObj
types after upgrading to Storybook v8. It's saying all arg types arePartial<MyComponent>
no matter what. The type itself hasinfer
, but that's inferring the wrong type for some reason.Before (v7)
Heavily simplified:
After (v8)
Generics don't match Storybook's docs
After going through the reproduction, I noticed this project has the generics passed incorrectly. I changed them to match the TypeScript reproduction, but it didn't fix it.
Looking further, it appears to be an issue with optional props (discriminated unions) where in one case they're required, in another case they're optional and never.
I modified the Button and its stories in the reproduction:
Reproduction link
https://stackblitz.com/edit/github-q1puzq?file=src%2Fstories%2FButton.stories.tsx,src%2Fstories%2FButton.tsx&preset=node
Reproduction steps
Button.stories.tsx
.Primary
story has the wrong type forargs.actionLabel
even though a value is passed.System
Additional context
No response
The text was updated successfully, but these errors were encountered: