Open Goncalongt opened 1 year ago
I'm having the same exact issue with Storybook 8.0.4
!
The children
type in the args
doesn't match the options
keys, but it still requires me to pass the ReactElement
...
Although the "Dealing with complex values" documentation using the mapper for the JSX values is recommended and examples show just that 🤷🏻♂️
For now, I just silenced it with @ts-expect-error
:
const meta = {
title: '...',
component: ...,
tags: ['autodocs'],
argTypes: {
children: {
options: Object.keys(annotatorContent),
mapping: annotatorContent
}
}
} satisfies Meta<typeof WebtextsAnnotator>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Plaintext: Story = {
args: {
// @ts-expect-error: The enum is mapped to the page content
children: 'Plaintext'
}
};
But it is a flaw in the documentation and/or the StoryObj
type inference 🤷🏻♂️
For now, the workaround I came up with is to use the React.PropsWithChildren
, which defines children?: ReactNode | undefined
. The ReactNode
covers the string
type, and it matches your mapped string too
Describe the bug
I am trying to create a story, and according to the docs, JSX Elements aren't JSON Serializable so I can't pass them directly as options to my controls. Due to that, I'm using the mapping feature to map the radio control string options to StyledComponents.
However, despite the code actually seeming to work, typescript complains that
'string' is not assignable to ReactElement
while defining the default value in the args property:I believe that this is a bug, but I can also be doing something wrong, any feedback?
To Reproduce
No response
System
Additional context
I have tried omitting that line, but I get the following error:
I have also tried assigning the value directly to the children arg/prop:
but I get the following warning in the console: