Storybook: Incorrect typescript typings with addon-jest's `withTests`

Created on 12 Sep 2019  路  9Comments  路  Source: storybookjs/storybook

addDecorator(withTests({ results })); leads to a TypeScript error.

Argument of type '(args_0: string | (() => void), args_1: { kind: string; parameters: AddonParameters; }) => void | ((storyFn: () => void, { kind }: { kind: string; }) => void)' is not assignable to parameter of type 'StoryDecorator'.
  Types of parameters 'args_1' and 'context' are incompatible.
    Property 'parameters' is missing in type '{ kind: string; story: string; }' but required in type '{ kind: string; parameters: AddonParameters; }'.ts(2345)

It looks like the return type of withTests is not compatible with the accepted argument type of addDecorator.

To Reproduce
In a TypeScript project:

...
import { withTests } from '@storybook/addon-jest';
import results from '../jest-test-results.json';

...
addDecorator(withTests({ results }));

Dependencies
@storybook/react: 5.1.11
@storybook/addon-jest: ^5.1.11

jest bug typescript

Most helpful comment

Egads!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.19 containing PR #8410 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

Thanks @shilman @CodeByAlex
It is working now.

All 9 comments

@rakeshpai Is this fixed in 5.2? addon-jest got a nice overhaul from @CodeByAlex and I'm betting he fixed it 馃槅

@rakeshpai I鈥檒l check on this and fix it if it doesn鈥檛 work

Just tried this with "@storybook/addon-jest": "^5.2.0-rc.11", and I get a very similar error (same code as before).

Argument of type 'DecoratorFunction<unknown>' is not assignable to parameter of type 'StoryDecorator'.
  Types of parameters 'c' and 'context' are incompatible.
    Type '{ kind: string; story: string; }' is missing the following properties from type 'StoryContext': id, name, parametersts ts(2345)

Thanks for looking into this!

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@CodeByAlex We got the same error in "@storybook/addon-jest": "^5.2.3"
Please let us know once you deploy the latest version.

Egads!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.19 containing PR #8410 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

Hello @shilman, addon-Info not working in @storybook/addon-info 5.2.3. and i am using react with typescript and following https://github.com/storybookjs/storybook/tree/master/addons/info url for implementing addon. but it is showing an error.

Property 'story' is missing in type 'StoryContext' but required in type '{ kind: string; story: string; }'

Egads!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.19 containing PR #8410 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

Thanks @shilman @CodeByAlex
It is working now.

Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.5 containing PR #8410 that references this issue. Upgrade today to try it out!

Was this page helpful?
0 / 5 - 0 ratings