question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setupServer / setupWorker type issues on ts strict mode

See original GitHub issue

Describe the bug

After upgrading to 0.21.0 typescript in strict mode is complaining when registering handlers to setupServer or setupWorker.

Tried it both using the new RequestBodyType and without.

Environment

  • msw: 0.21.0
  • nodejs: 12.18.3
  • npm: 6.14.6

To Reproduce

Steps to reproduce the behavior:

  1. Clone https://github.com/deini/msw-types
  2. npm install
  3. npm run test

Expected behavior

No typing errors

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kettanaitocommented, Sep 12, 2020

@aldis-ameriks, @emmenko, thank you for the follow up! I’ve issued https://github.com/mswjs/msw/pull/382 where we drop all the unknown generics altogether. Could you see if that PR fixes your usage? Thanks.

1reaction
aldis-amerikscommented, Sep 12, 2020

After pulling 0.21.1, I’m seeing these types of typing errors.

Type error: Argument of type 'ResponseTransformer<{ errors: Partial<GraphQLError>[]; }>' is not assignable to parameter of type 'ResponseTransformer<unknown>'.
137
  Types of parameters 'res' and 'res' are incompatible.
138
    Type 'MockedResponse<unknown>' is not assignable to type 'MockedResponse<{ errors: Partial<GraphQLError>[]; }>'.
139
      Type 'unknown' is not assignable to type '{ errors: Partial<GraphQLError>[]; }'.
Read more comments on GitHub >

github_iconTop Results From Across the Web

setupServer() - Api - Mock Service Worker Docs
This function is designed for NodeJS environment. If looking for a way to apply API mocking in a browser environment, consider using setupWorker...
Read more >
How strict is Typescript's strict mode? - DEV Community ‍ ‍
According to the docs, when Typescript strict mode is set to on, it will validate your code using the strict type rules under...
Read more >
msw: Versions - Openbase
Fixes type annotations of ResponseTransformer to drop the usage of the unknown generics causing type violations in strict mode (#381, #382). 0.21.1. 2...
Read more >
Msw With React - Dennis O'Keeffe Notes
4export const worker = setupWorker(...handlers); ... StrictMode> ... 13// if you need to add a handler after calling setupServer for some specific test....
Read more >
How to develop an offline Front-End app with mock data
This kind of seamless integration is what we are aiming for today! ... the browser.ts file dynamically only when we are in development...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found