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.

Question: why i'm getting typescript error by using msw

See original GitHub issue

Describe the bug

Hi, just discovered awesome msw. Time to try it out. I used CRA for my test application. Unfortunately i’m getting following error during compilation and executing npm start.

TypeScript error in /node_modules/msw/lib/types/utils/internal/compose.d.ts(3,12):
',' expected.  TS1005

    1 | declare type ArityOneFn = (arg: any) => any;
    2 | declare type PickLastInTuple<T extends any[]> = T extends [
  > 3 |     ...rest: infer U,
      |            ^
    4 |     argn: infer L
    5 | ] ? L : never;
    6 | declare type FirstFnParameterType<T extends any[]> = Parameters<PickLastInTuple<T>>[any];

Not sure what i’ve done wrong. Please sorry for that stupid question. So here I am and friendly asking for some help or hints. Here is my setup:

Environment

  • msw: 0.24.1
  • nodejs: 12.18.3
  • npm: 6.14.7

Please also provide your browser version. Chrome Version 87.0.4280.67

To Reproduce

Steps to reproduce the behavior:

  1. Installed msw by npm i -D msw
  2. Configured setupTest.ts
import { server } from './test/server'
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

  1. Configured /src/test/server.ts
import { handlers } from './server-handlers'
import { rest } from 'msw'
import { setupServer } from 'msw/node'
const server = setupServer(...handlers)

export { server, rest }
  1. Configured /src/test/server-handlers.ts
import { fetchControllerMock } from 'functions/mock/ApiMock'
import { rest } from 'msw' // msw supports graphql too!

const handlers: any = [
    rest.get('**/api/**', async (req, res, ctx) => {
        const data = await fetchControllerMock('abc', 'success')
        return res(ctx.json(data))
    }),
]
export { handlers }
  1. My `ts-config.json``
{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es2018",
    "outDir": "./build",
    "sourceMap": false,
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "noEmit": true
  },
  "include": [
    "src",
  ],
  "exclude": [
    "build",
    "node_modules",
    "test"
  ]
}

Expected behavior

no compilation errors.

Screenshots

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
chrisguttandincommented, Dec 3, 2020

Yes, I think so. As far as I know that wasn’t an explicit decision but the usage of variadic tuples implies that.

2reactions
chrisguttandincommented, Dec 3, 2020

Hi @x1core, the error looks like your version of TypeScript doesn’t yet support Variadic Tuple Types. Do you maybe use a TypeScript version below 4.0?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Mock Service Worker not installed in React project with ...
I want to include Mock Service Worker into my React project with Typescript support, but as soon as I run npm install msw...
Read more >
Type-safe API mocking with Mock Service Worker and ...
I 've got a question - Is it possible to add types for query params? For example when we want to mock a...
Read more >
Mocking an API request with Mock Service Worker and ...
I'm using Blogflow.io as a means to learn Typescript while simultaneously ... Mock Service Worker (MSW) provides a simple way to intercept these...
Read more >
Frequently Asked Questions - Storybook - JS.ORG
Why aren't my MDX 2 stories working in Storybook? Why can't I import my own stories into MDX 2? Why are my mocked...
Read more >
How to fix Jest and Mock Service Worker integration errors
After the integration with MSW was done, I saw this error when I tried to run the jest tests. It is very strange...
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