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.

Screenshot 2023-06-21 at 12 53 52 Screenshot 2023-06-21 at 12 54 51
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

https://stackblitz.com/edit/github-w3gat5?file=tsconfig.json,src%2Fstories%2FMainComponent.stories.tsx&preset=node

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)

Most upvoted comments

Hi, I’m still seeing this bug now that subcomponents support 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

subcomponents: {
  Component: Component as React.ComponentType<unknown>,
},

fyi/related: Please keep in mind that we might drop support for subcomponents altogether. Follow the discussion here: #20782

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:

same here. any news?

Still happening on v8.2.4

Still happening