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]: 7.6.4 - Module '"@storybook/addon-actions/decorator" "Type 'unknown' cannot be assigned to type 'StoryFnHtmlReturnType'" #25170

Closed
Gabriel-Lara-del-Olmo opened this issue Dec 11, 2023 · 9 comments

Comments

@Gabriel-Lara-del-Olmo
Copy link

Describe the bug

I´ve migrated storybook addons to latest version 7.6.4 and the decorator wihtActions have been broken by the update, and can´t compile the storybook.
It looks like the last version broke the package.

To Reproduce

It reproduces with version 7.6.4 of @storybook/addon-actions/decorator, but not with 7.5.X of less.

Captura de pantalla 2023-12-11 a las 14 24 35

System

I´ve using storybook 7.6.4 in Stencil project with version 4.4.0. It reproduces in any operative system.

Additional context

No response

@shilman
Copy link
Member

shilman commented Dec 24, 2023

Do you a have a reproduction repo you can share? If not, can you create one? Go to https://storybook.new or see repro docs. Thank you! 🙏

@Gabriel-Lara-del-Olmo
Copy link
Author

Gabriel-Lara-del-Olmo commented Dec 26, 2023

Yeah i can provide it, i need few hours thanks. But investigated the problem, i think is the same here: #22384

But with the @storybook/html plugin and not /react

Type '(storyFn: PartialStoryFn<T, Args>) => T["storyResult"]' is not assignable to type
'DecoratorFunction<HtmlRenderer, typeof UiButton>'.Type 'unknown' is not assignable to type
'StoryFnHtmlReturnType'.

 L75:    },
 L76:    decorators: [withActions],
 L77:  };

Copy link
Contributor

Hi there! Thank you for opening this issue, but it has been marked as stale because we need more information to move forward. Could you please provide us with the requested reproduction or additional information that could help us better understand the problem? We'd love to resolve this issue, but we can't do it without your help!

@github-actions github-actions bot added the Stale label Jan 17, 2024
@jiayike
Copy link

jiayike commented Jan 23, 2024

I'm facing the same issue with storybook v7.6.10 and able to replicate it in the v8.0.0-alpha.13.

Seems to be happening after PartialStoryFn type is copied from @storybook/types to decorator.d.ts of addon-actions is causing the issue. Not exactly sure why though

Reproduction repo here:
https://stackblitz.com/edit/github-ytftux?file=src%2Fstories%2FButton.stories.ts&preset=node

@m-akinc
Copy link

m-akinc commented Feb 8, 2024

Also ran into this. In every story with decorators: [withActions], I get the error:

TS2322: Type '<T extends Renderer>(storyFn: PartialStoryFn<T, Args>) => T["storyResult"]' is not assignable to type 'DecoratorFunction<HtmlRenderer, { open: boolean; title: string; text: string; severity: "error" | "information" | "default" | "warning"; action: ActionType; preventDismiss: boolean; titleHidden: boolean; toggle: unknown; usedLabels: null; }>'.
  Type 'unknown' is not assignable to type 'StoryFnHtmlReturnType'.

History:

While trying to fix a bug about a missing lib/types/dist module, @ndelangen added a type to the withActions decorator. I believe from that point on, this problem has existed (see this comment reporting the type error for the first time). @kasperpeulen seems to have made an attempt to fix this by changing the type, but as far as I can tell, that only changed the wording of the error message.

From what I can tell, the issue is that withActions used to be implicitly typed as (...args: any) => any (a.k.a MakeDecoratorResult), and that was compatible with DecoratorFunction<HtmlRenderer, ...>. But later,withActions was given an explicit type where the generic type parameter defaults to Renderer. This is not compatible with DecoratorFuction<HtmlRenderer, ...>.

I've found two ways to avoid the error:

  1. Provide the renderer type when specifying the decorator:
decorators: [withActions<HtmlRenderer>]
  1. Redefine withActions. You do not even have to change the type.
import { withActions as withActionsOriginal } from '@storybook/addon-actions/decorator';
const withActions: <T extends Renderer>(
    storyFn: PartialStoryFn<T>
) => T['storyResult'] = withActionsOriginal;

I don't understand how 2 is any different than doing nothing, but it works.

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.
@vanessayuenn vanessayuenn modified the milestones: 8.0-RC, 8.0-Stable Feb 12, 2024
@kasperpeulen
Copy link
Contributor

@m-akinc I can not reproduce this in the latest v8 release:

import type { StoryObj, Meta } from '@storybook/html';
import { withActions } from '@storybook/addon-actions/decorator';
import { fn } from '@storybook/test';
import type { ButtonProps } from './Button';
import { createButton } from './Button';

const meta: Meta<ButtonProps> = {
  title: 'Example/Button',
  tags: ['autodocs'],
  render: (args) => {
    return createButton(args);
  },
  decorators: [withActions],
  args: { onClick: fn() },
};

export default meta;
type Story = StoryObj<ButtonProps>;

export const Primary: Story = {
  args: {
    primary: true,
    label: 'Button',
  },
};

tsc doesn't give any errors, can you make a repro for me against v8?

@r3dDoX
Copy link

r3dDoX commented Mar 9, 2024

For people running into this and searching a workaround in a WebComponents project, the correct generic type is:
decorators: [withActions<WebComponentsRenderer>]

@m-akinc
Copy link

m-akinc commented Mar 11, 2024

@kasperpeulen Looks like it is fixed in the 8.0.0 release. Great!

@kasperpeulen
Copy link
Contributor

@m-akinc Thanks for checking!

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

No branches or pull requests

7 participants