reg-viz / storycap

A Storybook Addon, Save the screenshot image of your stories :camera: via puppeteer.
https://www.npmjs.com/package/storycap
MIT License
701 stars 89 forks source link

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

Open koumura-a-tm opened 1 year ago

koumura-a-tm commented 1 year ago

@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 commented 9 months ago

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 commented 9 months ago

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],