From 6bf8aa03890f275e5eea2cfe8c15d6f9c3240eac Mon Sep 17 00:00:00 2001 From: Koichi Kiyokawa Date: Tue, 28 Feb 2023 20:28:47 +0900 Subject: [PATCH] refactor: make smarter by destructuring assignment --- src/__snapshots__/index.test.ts.snap | 5 +++-- src/index.ts | 5 +++-- test/generated/index.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/__snapshots__/index.test.ts.snap b/src/__snapshots__/index.test.ts.snap index e47be3d..046e8da 100644 --- a/src/__snapshots__/index.test.ts.snap +++ b/src/__snapshots__/index.test.ts.snap @@ -125,9 +125,10 @@ export const createBaseFetcher = ( body: Get }> ): Promise> => { + const { method, query, body } = opts as any return ownFetcher( - path + (\\"query\\" in opts ? \`?\${new URLSearchParams(opts.query as any)}\` : \\"\\"), - { method: opts.method, body: (opts as any).body } + path + (query ? \`?\${new URLSearchParams(query as any)}\` : \\"\\"), + { method, body } ) as any; }; }; diff --git a/src/index.ts b/src/index.ts index 9c3914b..9950df0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,9 +54,10 @@ export const createBaseFetcher = ( body: Get }> ): Promise> => { + const { method, query, body } = opts as any return ownFetcher( - path + ("query" in opts ? \`?\${new URLSearchParams(opts.query as any)}\` : ""), - { method: opts.method, body: (opts as any).body } + path + (query ? \`?\${new URLSearchParams(query as any)}\` : ""), + { method, body } ) as any; }; }; diff --git a/test/generated/index.ts b/test/generated/index.ts index 518d614..baf583b 100644 --- a/test/generated/index.ts +++ b/test/generated/index.ts @@ -122,9 +122,10 @@ export const createBaseFetcher = ( body: Get }> ): Promise> => { + const { method, query, body } = opts as any return ownFetcher( - path + ("query" in opts ? `?${new URLSearchParams(opts.query as any)}` : ""), - { method: opts.method, body: (opts as any).body } + path + (query ? `?${new URLSearchParams(query as any)}` : ""), + { method, body } ) as any; }; };