hrsh7th / msw-snapshot

Transparently create an API cache for testing.
6 stars 2 forks source link

error TS2694: Namespace '"bla/node_modules/msw/lib/index"' has no exported member 'DefaultRequestBody'. #2

Closed Maxim-Mazurok closed 11 months ago

Maxim-Mazurok commented 1 year ago

Getting the following error from tsc --noEmit:

error TS2694: Namespace '"C:/Users/maxim.mazurok/transactions/legacy/groceries/honey/node_modules/msw/lib/index"' has no exported member 'DefaultRequestBody'.

Solved by using DefaultBodyType instead of DefaultRequestBody, will create PR soon

hrsh7th commented 1 year ago

Thank you. It seems to not follow the latest msw 😓

Maxim-Mazurok commented 1 year ago

Ah, actually since types are generated automatically I believe that just doing npm i msw@latest && npm run build and publishing will be enough to fix this, and since you'll be the one publishing anyway probably not much sense for me creating this tiny PR...

I'm using the following patch for now:

TODO: remove after https://github.com/hrsh7th/msw-snapshot/issues/2 is closed
diff --git a/node_modules/msw-snapshot/dist/cjs/index.d.ts b/node_modules/msw-snapshot/dist/cjs/index.d.ts
index 18109fb..8fe6d7c 100644
--- a/node_modules/msw-snapshot/dist/cjs/index.d.ts
+++ b/node_modules/msw-snapshot/dist/cjs/index.d.ts
@@ -28,4 +28,4 @@ declare type Snapshot = {
 /**
  * Create snapshot RequestHandler.
  */
-export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultRequestBody>>;
+export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
diff --git a/node_modules/msw-snapshot/dist/dts/index.d.ts b/node_modules/msw-snapshot/dist/dts/index.d.ts
index 18109fb..8fe6d7c 100644
--- a/node_modules/msw-snapshot/dist/dts/index.d.ts
+++ b/node_modules/msw-snapshot/dist/dts/index.d.ts
@@ -28,4 +28,4 @@ declare type Snapshot = {
 /**
  * Create snapshot RequestHandler.
  */
-export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultRequestBody>>;
+export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
diff --git a/node_modules/msw-snapshot/dist/esm/index.d.ts b/node_modules/msw-snapshot/dist/esm/index.d.ts
index 18109fb..8fe6d7c 100644
--- a/node_modules/msw-snapshot/dist/esm/index.d.ts
+++ b/node_modules/msw-snapshot/dist/esm/index.d.ts
@@ -28,4 +28,4 @@ declare type Snapshot = {
 /**
  * Create snapshot RequestHandler.
  */
-export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultRequestBody>>;
+export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;

So no rush, but would be great to fix that sometime, thank you!

hrsh7th commented 1 year ago

I've published the v0.2.0. Thank you!

hrsh7th commented 1 year ago

I forgot the npm i msw@latest. Sorry.

Maxim-Mazurok commented 1 year ago

I've tried v1.1.0 and it seems to produce a different error now:

tsc --noEmit
node_modules/msw-snapshot/dist/dts/index.d.ts:32:107 - error TS2307: Cannot find module 'msw/lib/SetupApi-b2f0e5ac' or its corresponding type declarations.

32 export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw/lib/SetupApi-b2f0e5ac").c>>;
                                                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 1 error in node_modules/msw-snapshot/dist/dts/index.d.ts:32

This is a bit weird because I do have node_modules\msw\lib\SetupApi-b2f0e5ac.d.ts file.

Also, import("msw/lib/SetupApi-b2f0e5ac").c seems to resolve to DefaultBodyType so this patch solves the issue:

diff --git a/node_modules/msw-snapshot/dist/dts/index.d.ts b/node_modules/msw-snapshot/dist/dts/index.d.ts
index dfc4d67..8f420f5 100644
--- a/node_modules/msw-snapshot/dist/dts/index.d.ts
+++ b/node_modules/msw-snapshot/dist/dts/index.d.ts
@@ -1,4 +1,4 @@
-import { MockedRequest } from "msw";
+import { DefaultBodyType, MockedRequest } from "msw";
 export * from './mask';
 export type PlainObject = string | number | null | boolean | PlainObject[] | {
     [k: string]: PlainObject;
@@ -29,4 +29,4 @@ type Snapshot = {
 /**
  * Create snapshot RequestHandler.
  */
-export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw/lib/SetupApi-b2f0e5ac").c>>;
+export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<DefaultBodyType>>;
hrsh7th commented 1 year ago

I published the v1.2.0 with npmi -D msw@latest.

I can't understand why this problem is occurred. sorry.

Maxim-Mazurok commented 1 year ago

I've tried v1.2.0 and I still have a problem with that import: export declare const snapshot: (config: SnapshotConfig) => import("msw").RestHandler<MockedRequest<import("msw/lib/SetupApi-f4099ef3").c>>; image

I'll be using the patch mentioned above for the time being. A bit annoying because every time msw updates - the hash updates and invalidates the path. But not a deal breaker, cheers!

hrsh7th commented 11 months ago

The new msw was release and the msw-snapshot supports it now.

IMO, this issue is obsoleted at the moment. Close for now.