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

[Bug]: @storybook/addon-actions: Type 'Addon_DecoratorFunction<unknown>' is not assignable to type 'DecoratorFunction<ReactRenderer, { #22384

Closed
JeffreyStevens opened this issue May 3, 2023 · 4 comments · Fixed by #22455

Comments

@JeffreyStevens
Copy link

JeffreyStevens commented May 3, 2023

Describe the bug

Cannot use withActions from @storybook/addon-actions/decorator as it throws a type error:

ERROR in src/stories/components/routes/RouteNoteDialog.stories.tsx:89:18
TS2322: Type 'Addon_DecoratorFunction<unknown>' is not assignable to type 'DecoratorFunction<ReactRenderer, { showRouteNoteDialog: boolean; handleCancelNote: () => void; handleSaveNote: () => void; routeNote: IRouteNote | null; setRouteNote: (value: IRouteNote | null) => void; title: string; }>'.
  Types of parameters 'c' and 'c' are incompatible.
    Type 'StoryContext<ReactRenderer, { showRouteNoteDialog: boolean; handleCancelNote: () => void; handleSaveNote: () => void; routeNote: IRouteNote | null; setRouteNote: (value: IRouteNote | null) => void; title: string; }>' is not assignable to type 'StoryContext<Addon_ReturnTypeFramework<unknown>, Args>'.
      Type 'StoryContext<ReactRenderer, { showRouteNoteDialog: boolean; handleCancelNote: () => void; handleSaveNote: () => void; routeNote: IRouteNote | null; setRouteNote: (value: IRouteNote | null) => void; title: string; }>' is not assignable to type '{ hooks: unknown; viewMode: ViewMode$1; originalStoryFn: StoryFn<Addon_ReturnTypeFramework<unknown>, Args>; }'.
        Types of property 'originalStoryFn' are incompatible.
          Type 'StoryFn<ReactRenderer, Args>' is not assignable to type 'StoryFn<Addon_ReturnTypeFramework<unknown>, Args>'.
            Type 'LegacyStoryFn<ReactRenderer, Args>' is not assignable to type 'StoryFn<Addon_ReturnTypeFramework<unknown>, Args>'.
              Type 'LegacyStoryFn<ReactRenderer, Args>' is not assignable to type 'LegacyStoryFn<Addon_ReturnTypeFramework<unknown>, Args>'.
                Types of parameters 'context' and 'context' are incompatible.
                  Type 'StoryContext<Addon_ReturnTypeFramework<unknown>, Args>' is not assignable to type 'StoryContext<ReactRenderer, Args>'.
                    Type 'StoryContext<Addon_ReturnTypeFramework<unknown>, Args>' is not assignable to type '{ hooks: unknown; viewMode: ViewMode$1; originalStoryFn: StoryFn<ReactRenderer, Args>; }'.
                      Types of property 'originalStoryFn' are incompatible.
                        Type 'StoryFn<Addon_ReturnTypeFramework<unknown>, Args>' is not assignable to type 'StoryFn<ReactRenderer, Args>'.
                          Type 'LegacyStoryFn<Addon_ReturnTypeFramework<unknown>, Args>' is not assignable to type 'StoryFn<ReactRenderer, Args>'.
                            Type 'LegacyStoryFn<Addon_ReturnTypeFramework<unknown>, Args>' is not assignable to type 'LegacyStoryFn<ReactRenderer, Args>'.
                              Types of parameters 'context' and 'context' are incompatible.
                                Type 'StoryContext<ReactRenderer, Args>' is not assignable to type 'StoryContext<Addon_ReturnTypeFramework<unknown>, Args>'.
                                  Type 'StoryContext<ReactRenderer, Args>' is not assignable to type '{ hooks: unknown; viewMode: ViewMode$1; originalStoryFn: StoryFn<Addon_ReturnTypeFramework<unknown>, Args>; }'.
                                    Types of property 'originalStoryFn' are incompatible.
                                      Type 'StoryFn<ReactRenderer, Args>' is not assignable to type 'StoryFn<Addon_ReturnTypeFramework<unknown>, Args>'.
                                        Type 'LegacyStoryFn<ReactRenderer, Args>' is not assignable to type 'StoryFn<Addon_ReturnTypeFramework<unknown>, Args>'.
    87 |     title: 'Admin Unit/RouteNoteDialog', // how to refer to the component in the sidebar (optional)
    88 |     component: RouteNoteDialogApp, // the component itself or a wrapper function
  > 89 |     decorators: [withActions, (story) => <ReduxProvider store={store}>{story()}</ReduxProvider>],

To Reproduce

Edit RouteNoteDialog.stories.tsx lines 74-76 to reproduce.

GitHub:
https://github.com/JeffreyStevens/addon-actions.git

Chromatic:
https://64527bd174e7442f19279395-jzhubeajpz.chromatic.com/?path=/story/admin-unit-routenotedialog--note

System

Environment Info:

  System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.0.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.6.4 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Edge: 112.0.1722.68
    Safari: 16.4
  npmPackages:
    @storybook/addon-essentials: ^7.0.7 => 7.0.8 
    @storybook/addon-interactions: ^7.0.7 => 7.0.8 
    @storybook/addon-links: ^7.0.7 => 7.0.8 
    @storybook/blocks: ^7.0.7 => 7.0.8 
    @storybook/jest: ^0.1.0 => 0.1.0 
    @storybook/preset-create-react-app: ^7.0.7 => 7.0.8 
    @storybook/react: ^7.0.7 => 7.0.8 
    @storybook/react-webpack5: ^7.0.7 => 7.0.8 
    @storybook/testing-library: ^0.0.14-next.2 => 0.0.14-next.2

Additional context

Started failing with 7.0.7 version.

@JeffreyStevens JeffreyStevens changed the title [Bug]: Type 'Addon_DecoratorFunction<unknown>' is not assignable to type 'DecoratorFunction<ReactRenderer, { [Bug]: @storybook/addon-actions: Type 'Addon_DecoratorFunction<unknown>' is not assignable to type 'DecoratorFunction<ReactRenderer, { May 3, 2023
@shilman
Copy link
Member

shilman commented May 4, 2023

@ndelangen this must be due to https://github.com/storybookjs/storybook/pull/22261/files

@kasperpeulen commented on it here #22261 (comment) and I also asked you about it when we chatted about it in person. If we had type tests, could we have avoided this?

@kasperpeulen
Copy link
Contributor

I think we should definitely add a type test for this! Will look at it.

@kasperpeulen
Copy link
Contributor

kasperpeulen commented May 8, 2023

@shilman @ndelangen

The types added in #22261 are not working for code that is actually imported by users.

I thought approved that PR because I thought they were not actually used.

Making a correct type of a decorator that can be used for any renderer is tricky. This is sadly enough:

const withActions: DecoratorFunction<Renderer>;

Basically, you want something like:

declare const withActions<T extends Renderer>: DecoratorFunction<T>;

However, this is not a syntax that TS support. You basically have to inline the function type of DecoratorFunction, which looks like this:

const withActions: <T extends Renderer>(storyFn: PartialStoryFn<T>) => T['storyResult']

Added that in this PR:
#22455

This needs to be done for every decorator in this PR, that needs to be imported:
#22261

You can not annotate an array of decorators with this. It needs to be done for every individual decorator I believe.

@github-project-automation github-project-automation bot moved this from Empathy Backlog to Done in Core Team Projects May 17, 2023
@shilman
Copy link
Member

shilman commented May 19, 2023

Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.20 containing PR #22455 that references this issue. Upgrade today to the @future NPM tag to try it out!

npx sb@next upgrade --tag future

jattasNI added a commit to ni/nimble that referenced this issue Jun 23, 2023
…enable audit for prod (#1322)

# Pull Request

## 🤨 Rationale

Fixes #1317.

The `npm audit` of production dependencies was failing because of deps
that Storybook brought in. But Storybook should really be a dev
dependency.

Storybook is listed as a production dependency because it's in
`peerDependencies` in the root `package.json`. We added it there in
[this
commit](321cdd3)
of the PR that migrated us to Storybook 7. I believe the rationale was
that it was necessary to apply [a
patch](https://github.com/ni/nimble/blob/main/patches/%40storybook%2Bhtml%2B7.0.0.patch)
to the package. (I'd like to remove that patch but I think it's not
possible until storybookjs/storybook#22384 is
available. Currently it's only released in an alpha branch)

## 👩‍💻 Implementation

1. Remove `@storybook/html` from `peerDependencies` in the root
`package.json`
2. `git clean -fdx`
3. `npm install` to regenerate `package-lock.json`
4. Re-enable audit for all severity levels for prod dependencies

## 🧪 Testing

I locally verified that the patch was still applied to the file inside
node_modules. If it isn't applied, I believe we'd see a build error.

I locally verified that `npm audit --only=prod` succeeds now.

Otherwise relying on the PR build.

## ✅ Checklist

<!--- Review the list and put an x in the boxes that apply or ~~strike
through~~ around items that don't (along with an explanation). -->

- [ ] I have updated the project documentation to reflect my changes or
determined no changes are needed.
rajsite pushed a commit to ni/nimble that referenced this issue Feb 9, 2024
# Pull Request

## 🤨 Rationale

Wanted to see if there were any improvements.

## 👩‍💻 Implementation

- Bumped version from 7.4.0 to 7.6.13
- Had to work around an
[issue](storybookjs/storybook#25170) related
to the typing of `withActions` decorator of actions add-on.
~~Re-exporting `withActions` from our Storybook utilities file with a
type that works (based on [comment in related
issue](storybookjs/storybook#22384 (comment)
Now providing type argument to generic `withActions` function.
- Marked docs support disabled in `addon-essentials` since we import
that addon separately (`addon-docs`) so we can configure it. Not sure if
this improves anything, but it doesn't seem to hurt.
- Also fixes #1639

## 🧪 Testing

Ran Storybook. `npm run storybook` seems to get everything ready about
25% faster (40s -> 30s).

## ✅ Checklist

<!--- Review the list and put an x in the boxes that apply or ~~strike
through~~ around items that don't (along with an explanation). -->

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants