Skip to content
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

Default export CSF 'component' typing for class component #12056

Closed
dmarcautan opened this issue Aug 16, 2020 · 5 comments
Closed

Default export CSF 'component' typing for class component #12056

dmarcautan opened this issue Aug 16, 2020 · 5 comments

Comments

@dmarcautan
Copy link

Describe the bug
Typescript will error on the following block when MyComponent is defined as class component:
export default { title: "MyComponents/MyComponent", component: MyComponent, } as Meta;

'component' property typed with:
type ReactComponent = Component | FunctionComponent<any>;

'Component' is instance type definition but 'FunctionComponent' is functional component TYPE.

@shilman
Copy link
Member

shilman commented Aug 16, 2020

'Component' is instance type definition but 'FunctionComponent' is functional component TYPE.

Can you elaborate on this?

@dmarcautan
Copy link
Author

dmarcautan commented Aug 17, 2020

'Component' is instance type definition but 'FunctionComponent' is functional component TYPE.

Can you elaborate on this?

@shilman
Consider the fragment:

class MyComponent extends Component {

}

export default {
	title: "Controls/MyComponent",
	component: MyComponent,
  } as Meta;

Casting default export as Meta will generate TS compilation error here because 'component' field expects Component implementation. MyComponent is constructor function and doesn't implement Component but is actually an implementation of ComponentClass. We can fix the error if we provide 'component' field with new MyComponent({}) but I assumed the field should be provided with component type ( as defined in React typings: type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>). Or do I miss the point?

@shilman
Copy link
Member

shilman commented Aug 17, 2020

@dmarcautan I think you're right. I pretty much only ever use FC, so I didn't know about ComponentClass. Will fix!

@shilman
Copy link
Member

shilman commented Aug 17, 2020

Ooh-la-la!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.12 containing PR #12072 that references this issue. Upgrade today to try it out!

Closing this issue. Please re-open if you think there's still more to do.

@shilman
Copy link
Member

shilman commented Aug 20, 2020

Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.15 containing PR #12110 that references this issue. Upgrade today to try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants