Open maxicasa opened 11 months ago
I also encountered the problem of supporting components with generics, it would be nice to get a solution on what to do in such cases
How temp solution, i use this way
same problem, this error also occurs in normal component
@kasperpeulen, any idea why the issue occurs?
Hey guys, just got the same issue. Does anybody found acceptable workaround?
Same problem with React!
With this type
Temporary workaround by adding | string
line 12 but acts like as a any
...
How temp solution, i use this way
Thanks, @Gumper-x. This worked for me. I was able to adjust it to make it stricter (and remove the unknown
conversion):
const meta = {
title: 'MyComponent',
component: MyComponent as Record<keyof typeof MyComponent, unknown>,
// ...
} satisfies Meta<typeof MyComponent>;
I am using the following.
type GenericMeta<C> = Omit<Meta<C>, "component"> & {
component: Record<keyof C, unknown>
}
const meta = {
title: "MyComponent",
component: MyComponent,
args: {
"modelValue": "string",
},
// ...
} satisfies GenericMeta<typeof MyComponent<string>>;
Describe the bug
I am trying to use a generic component with the story but it fails because the inferred type is wrong. For example:
And the story:
The typescript error:
I tried to change the signature of the story with this, but the problem remains:
The only workaround I've found is to use a simple cast of the meta, but I lose the type check for the
meta
object:Is it possibile to use generic component with story?
To Reproduce
The issue is visible if you download the project and open it from vscode: https://stackblitz.com/edit/github-sgrypj?file=src%2Fstories%2FButton.stories.tsx
System
Additional context
No response