New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript compile errors with CSF & Knobs #10335
Comments
Hey @Benwick91, I might be able to help you with that! 1 - In your button, create a type for your variation and export it. // Button.tsx
import React from 'react'
export type Variant = 'secondary' | 'inverted' | undefined
type Props = {
variant: Variant
}
export const Button: React.FC<Props> = ({ variant }) => {
return (
<>...Your implementation with {variant} here...</>
)
} 2 - In your story file, define the type of the option in the select function like: // Button.stories.tsx
import React, { FunctionComponent } from 'react'
import { select, withKnobs } from '@storybook/addon-knobs'
import { Button, Variant } from './Button'
const options: Record<string, Variant> = {
Primary: undefined,
Secondary: 'secondary',
Inverted: 'inverted',
}
export const Simple: FunctionComponent = () => (
<Button variant={select<Variant>('Variant', options, 'secondary')}>Text</Button>
)
export default {
component: Button,
title: 'Button',
} 3 - Make sure you are adding the For the Modal issue, if you have the Also, |
@yannbf Thank you so much!!! That is the way to get it worked. Thanks for the good and detailed answer. |
No worries, happy to help! |
I'm getting this error with the example components I get from |
Describe the bug
TS Error with Knobs
If I use especially the select Option from Knobs with TypeScript, the TypeScript Compiler throws an error.
TS Error with CSF
The error Message with Knobs:
Type 'string' is not assignable to type '"secondary" | "inverted" | undefined'.
Also the compiler throws an error with the components, which only has a default export (I use
declaration: true
in the tsconfig) - Or can I exclude the stories when I compile?error TS4082: Default export of the module has or is using private name 'ModalProps'.
Expected behavior
I want to use Knobs and the select Option with TypeScript and want to use the Components with default export without TypeScript Compile errors.
Code snippets
My usage of Knobs in the story:
My Components export:
And Import in the story:
import Modal from './Modal';
The error doesn't come when I export the Interface, too:
and export the default Component at the end:
export default Modal;
But this seems to be not a good way, or am I wrong?
System:
Can somebody help me? I can run storybook without problems, but I need to compile the TypeScript for a package and this doesn't work with these errors. Thank you very much!
The text was updated successfully, but these errors were encountered: