Should CSF Next meta.story() inherit from preview.meta args?
#33699
Replies: 1 comment
-
|
Hi @lancegliser! I'm Dosu and I’m helping the storybook team. CSF Next in Storybook 10.2+ is designed so that the args from preview.meta and meta.story() are combined, and the union must satisfy your component's required props. If all required args are provided in preview.meta, you can call meta.story() with empty args and TypeScript will accept it. If you split required args between meta and story, TypeScript checks the combined shape for validity. However, story args alone do not automatically inherit the meta args types—they must be combined to satisfy the component's requirements. If the combined meta and story args are missing required fields, TypeScript will error as expected. This is a limitation of the current implementation and TypeScript's inference, not a bug (example test). For best results and to avoid type errors—especially with custom args—explicitly type your render function's args parameter as an intersection of your component's props and any custom args. For example: type DialogArgs = DialogProps & { customArg?: string };
const meta = preview.meta({
component: Dialog,
render: (args: DialogArgs) => { /* ... */ },
});This pattern helps TypeScript understand the full shape of args passed from both meta and story (see discussion). There are ongoing improvements to type inference, but explicit typing is still recommended for complex scenarios. If you have a more complex typing case, let me know and I can help with a more specific example. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Trying out 10.2's CSF next updates. I configured with
#storybook/using a tsconfig and it's that's working no issue.Stories themselves seem to have a typescript specific issue. Here's an example of a generic MUI dialog.
The actual rendering works and inherits it as you'd expect when it's running. It's just missing type chain inheritance. Have I missed something, or is this piece still in progress?
Additional information
No response
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions