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

getWorker() TS issue #65

Open
robcaldecott opened this issue Dec 7, 2021 · 1 comment
Open

getWorker() TS issue #65

robcaldecott opened this issue Dec 7, 2021 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@robcaldecott
Copy link

This is odd, the following code generates a TS error even though on the face of it the types look OK:

import { getWorker } from "msw-storybook-addon";

afterAll(() => {
  // ts(2339) error
  getWorker().close();
});

It seems to think close is missing from SetupApi but that doesn't make sense.

I have created a sample repo here:

https://github.com/robcaldecott/msw-storybook-addon-type-errors

Current workarounds are either // @ts-ignore or this:

import { SetupServerApi } from "msw/lib/types/node";

afterAll(() => {
  (getWorker() as SetupServerApi).close();
});

Better ideas are welcome.

@kettanaito
Copy link
Member

Hey, @robcaldecott. Thanks for reaching out.

We need to improve on our type annotations (and also rename getWorker, it made me believe you're referring to the Service Worker, when, in fact, the add-on properly assigns the api to the worker/server depending on the environment).

I wonder if one can do conditional types based on the environment. The least we can do right now is to make getWorker a generic function so that you could use it like this:

getWorker<SetupServerApi>().close()

@kettanaito kettanaito added the help wanted Extra attention is needed label Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants