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

Error: @storybook/react 7.3.2 withScreenshot in preview.tsx #810

Open
koumura-a-tm opened this issue Aug 24, 2023 · 2 comments
Open

Error: @storybook/react 7.3.2 withScreenshot in preview.tsx #810

koumura-a-tm opened this issue Aug 24, 2023 · 2 comments

Comments

@koumura-a-tm
Copy link

koumura-a-tm commented Aug 24, 2023

@storybook/react 7.3.2 withScreenshot in preview.tsx
I get an error.

storycap is still not compatible with storybook v7?

// preview.tsx - error text

Cannot assign type 'WithScreenshot' to type 'DecoratorFunction<ReactRenderer, { [x: string]: any; }>'.
   Parameters 'options' and 'fn' have incompatible types.
     Type 'PartialStoryFn<ReactRenderer, { [x: string]: any; }>' has no properties in common with type 'Partial<ScreenshotOptions>'.
// preview.tsx - example

import type { Preview } from '@storybook/react'
...
const preview: Preview = {
  loaders: [
    ...
  ],
  decorators: [
    (Story) => {
      ...
    },
    withScreenshot,
  ],
  parameters: {
    ...
  },
}

export default preview
@undesicimo
Copy link

undesicimo commented Nov 10, 2023

For 7.0? onwards, need to invoke decorator as a workaround.

// preview.tsx - example

import type { Preview } from '@storybook/react'
...
const preview: Preview = {
  loaders: [
    ...
  ],
  decorators: [
    (Story) => {
      ...
    },
    withScreenshot(), // <== invoke
  ],
  parameters: {
    ...
  },
}

export default preview

seems to be deprecated though?

@koumura-a-tm
Copy link
Author

koumura-a-tm commented Nov 24, 2023

Thank you for the answer from one perspective.
But that won't be the solution.

Isn't it written in the official documentation as below?
「Using withScreenshot as function is deprecated. 」
reference: https://github.com/reg-viz/storycap#withscreenshot

Because it should look like this:

// deprecated
decorators: [withScreenshot()],

And I do it like this.
However, I would like to avoid using any as much as possible.

// Solved with any
decorators: [withScreenshot as any],

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

No branches or pull requests

2 participants