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:
msw: 0.24.1nodejs: 12.18.3npm: 6.14.7Please also provide your browser version.
Chrome Version 87.0.4280.67
Steps to reproduce the behavior:
npm i -D mswimport { server } from './test/server'
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
/src/test/server.tsimport { handlers } from './server-handlers'
import { rest } from 'msw'
import { setupServer } from 'msw/node'
const server = setupServer(...handlers)
export { server, rest }
/src/test/server-handlers.tsimport { 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 }
{
"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"
]
}
no compilation errors.
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?
Hi, thanks for the quick reply. Indeed im using 3.9.7.
So msw requires >4.0.0?
Yes, I think so. As far as I know that wasn't an explicit decision but the usage of variadic tuples implies that.
Just tested with typescript 4.1.2 and it works <3. Thanks a lot. I'll close the issue
My bad, I didn't realize that is a 4.x feature. What would be the correct way to specify the required version of TypeScript?
Should we add an (optional) peer dependency for TypeScript?
How do you solve that without upgrading typescript? Do I have to downgrade msw?
=> 0.20.5 is the latest typescript v3 release
There is a tool called downlevel-dts that can be used to produce type definitions which are compatible with previous versions of TypeScript.
Most helpful comment
Yes, I think so. As far as I know that wasn't an explicit decision but the usage of variadic tuples implies that.