Question: why i'm getting typescript error by using msw
See original GitHub issueDescribe 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:
- Installed msw by
npm i -D msw
- Configured setupTest.ts
import { server } from './test/server'
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
- 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 }
- 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 }
- 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:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, I think so. As far as I know that wasn’t an explicit decision but the usage of variadic tuples implies that.
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?