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

refactor: change MswParameters and Context from type to interface in decorator.ts #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seriouslag
Copy link

@seriouslag seriouslag commented Feb 20, 2025

This is done to support typescript declaration merging.

I have code where I augment the storybook parameters,
This causes an error in the storybook when registering the mswLoader to the storybook loaders, which uses the MSW parameters, as they now do not match.

Changing from type to an interface allows consumers to augment the types.

The consumer could augment the storybook parameters type and the mswParamters type to match.

Example to augment the interfaces in consumer code after the PR's changes:

import { mswLoader } from 'msw-storybook-addon';
...

// modifying storybook's params
declare module '@storybook/react' {
  interface Parameters {
    router?: RouterParameters;
  }
}
// modifying addon's params
declare module 'msw-storybook-addon' {
  interface MswParameters {
    router?: RouterParameters;
  }
}

// register the loaders;
// without this PR and only augmenting the storybook Parameters there would be a type error here
const loaders: StorybookLoader[] = [mswLoader];

const preview: Preview = {
  parameters,
  decorators,
  loaders,
};

export default preview;

…decorator.ts

This is done to support typescript declaration merging.

There is code where we augment the parameters in react,
this causes an error in storybook when using the MSW parameters as they do not match

Changing from type to an interface allows the consumer to augment the types.
Copy link

vercel bot commented Feb 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
msw-storybook-addon ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 20, 2025 11:16pm

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

Successfully merging this pull request may close these issues.

1 participant