Preact integration doesn't seem to derive prop types correctly #33749
Replies: 2 comments 3 replies
-
|
Hi @rschristian! I'm Dosu and I’m helping the storybook team. You're not doing anything wrong—this is a limitation of Storybook's Preact integration. Unlike React, which uses To get type-safe stories with Preact, you need to explicitly provide the prop types to import type { Meta, StoryObj } from '@storybook/preact';
import { Button } from './Button';
interface Props {
text: string;
}
const meta: Meta<Props> = {
component: Button,
};
export default meta;
type Story = StoryObj<Props>;
export const Basic: Story = {};
export const Primary: Story = {
args: {
text: 'Click Me',
},
};This pattern ensures your stories are type-checked against your component's props. If you need to add custom args, use an intersection type (e.g., If you have a minimal reproduction that still doesn't work with explicit typing, please share it so we can dig deeper. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@rschristian not user error -- this is a known gap in the preact framework integration. workaround: pass your props type directly instead of const meta = {
component: Button,
} satisfies Meta<Props>; // Props, not typeof Button
export default meta;
type Story = StoryObj<Props>;
export const Basic = {
args: { text: 'Click Me' },
} satisfies Story;the root cause is that storybook uses the preact framework package just doesn't get the same type-level attention as react/vue. a few related issues have been filed but nothing has landed yet. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Not quite sure that this isn't user error, so opening here first.
Per the docs, Storybook should be able to correctly derive component prop types but I haven't found this to be the case with the Preact integration. In fact, there's seemingly no way to provide types in a type-safe manner.
Am I doing something wrong here?
Additional information
No response
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions