storybook: [Bug]: `subcomponents` meta property always invalid with TypeScript Strict mode for React
Describe the bug
When React projects TypeScript config has Strict mode enabled subcomponents meta property always shows TypeScript error for every subcomponent property. When Strict mode is disabled no error is happening.
Type '({ children }: RequiredChildrenProps) => Element' is not assignable to type 'ComponentType<unknown>'.
Type '({ children }: RequiredChildrenProps) => Element' is not assignable to type 'FunctionComponent<unknown>'.
Types of parameters '__0' and 'props' are incompatible.
Type 'unknown' is not assignable to type 'RequiredChildrenProps'.(2322)
To Reproduce
It is configured with strict: true.
System
Environment Info:
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.4.2 - /usr/local/bin/npm
npmPackages:
@storybook/addon-essentials: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/addon-interactions: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/addon-links: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/blocks: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/react: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/react-webpack5: ^7.1.0-alpha.37 => 7.1.0-alpha.37
@storybook/testing-library: ^0.1.1-next.0 => 0.1.1-next.0
Additional context
Issue is not present in Storybook 6.
subscomponents type in Storybook 6:
subcomponents?: Record<string, React.ComponentType<any>> | undefined
subscomponents type in Storybook 7:
ComponentAnnotations<ReactRenderer, MainComponentProps>.subcomponents?: Record<string, React.ComponentType<unknown>> | undefined
Probably the main issue is a change from React.ComponentType<any> to React.ComponentType<unknown>.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 39
- Comments: 17 (4 by maintainers)
Hi, I’m still seeing this bug now that
subcomponentssupport was added back in Storybook 8. I’m on version 8.0.6.Still happening on 8.0.8
@JReinhold this seems to have broken again with Storybook 9 - the type now uses internal Storybook core definition, not the csf package one. I’ve filed a PR to bring the fix into core as well, but pinging just in case you want to re-open this meanwhile.
I have raised a PR against @storybook/csf which as best I can see, fixes the underlying issue: https://github.com/ComponentDriven/csf/pull/103
This seems to work as a temporary solution until it’s fixed
for anyone tracking this, the subcomponents feature has been undeprecated as detailed by @JReinhold here:
https://github.com/storybookjs/storybook/issues/20782#issuecomment-1892178858
Given this - any chance of taking a look at this issue or the linked PR @JReinhold @valentinpalkovic?
Related:
+1
same here. any news?
Still happening on v8.2.4
+1
I believe this was fixed in https://github.com/ComponentDriven/csf/pull/103
Still happening