fix: Explicitly allow undefined type for table.type.summary
Closes storybookjs/storybook#27129
Allowing explicitly undefined as type for table.type.summary lets Story authors disable the automatic type summary while having strict TypeScript options. With exactOptionalPropertyTypes enforced, using undefined as a type was forbidden, as TypeScript would raise an error. With this change, it should be allowed.
Did you temporarily turn off exactOptionalPropertyTypes and see if passing undefined behaved like you expect? I don't have that setting turned on, and when I pass undefined for summary, it defaults back to the automatic type definition.
I then tried null as any and that worked as expected. So I'd think we'd need to allow null instead of undefined for this to actually fix the issue.
Maybe I'm missing something else?
Yes, we turned off exactOptionalPropertyTypes for the Storybook part of our repository. Writing the following does remove the automatic type definition like we wanted to in Storybook:
table: {
type: { summary: undefined },
},
We used to pass null instead of undefined, but since the upgrade to Storybook v8.1, the typechecking would not allow it and so we switched to undefined which had the same result for us.
Thank you @Hyzual – I'll see what else I may have different or what I might have missed.
OK, so finally got a chance to test null vs undefined more. I'm not sure why this works for you, but even with a brand new project it only omitted the type when I used null
I took the following steps:
- Create a new vite app (
npm create vite@latest story-demo -- --template react-ts) - Run
npx storybook@latest init - Tried to edit the generated
Button.stories.tsto remove the default type for thesizeprop.
undefined did not work
It still showed union as the type.
const meta = {
...
argTypes: {
...
size: {
table: { type: { summary: undefined } }
}
},
...
} satisfies Meta<typeof Button>;
null worked
Though of course it produces a typescript error:
...
size: {
table: { type: { summary: null } }
}
...
So I believe we the updated type should be:
type?: { summary?: string | null; detail?: string };
😲 ok. I'm fine with either undefined or null to be honest