#setProjectAnnotations has a broken type (testing-react)

2 messages · Page 1 of 1 (latest)

flat forge
#

Following the docs for testing-react with global config:
https://github.com/storybookjs/testing-react#global-config

import {setProjectAnnotations} from '@storybook/react';
import * as globalStorybookConfig from './.storybook/preview';

setProjectAnnotations(globalStorybookConfig);

I get the following TypeScript error:

setProjectAnnotations(globalStorybookConfig);
                      ~~~~~~~~~~~~~~~~~~~~~

S2345: Argument of type 'typeof import("/Users/me/project/.storybook/preview")' is not assignable to parameter of type 'ProjectAnnotations  | ProjectAnnotations []'.

This is my preview.ts file:

import type {Preview} from '@storybook/react';

const preview: Preview = {
    // my config here
}
export default preview;

I checked the type of Preview and it's

type Preview = ProjectAnnotations<ReactRenderer>;

So clearly, it's the correct type.

How do I resolve this?

#

This stops the TS error from showing up, but I'm not sure why it is happening in the first place.

import {Preview, setProjectAnnotations} from '@storybook/react';
import * as globalStorybookConfig from '../.storybook/preview';

// ...

setProjectAnnotations(globalStorybookConfig as Preview);