Skip to content

Commit

Permalink
refactor: make smarter by destructuring assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
KoichiKiyokawa committed Feb 28, 2023
1 parent 42feb29 commit 6bf8aa0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export const createBaseFetcher = (
body: Get<paths[Path], [Method, \\"requestBody\\", \\"content\\", \\"application/json\\"]>
}>
): Promise<Get<paths[Path], [Method, \\"responses\\", 200, \\"content\\", \\"application/json\\"]>> => {
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;
};
};
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export const createBaseFetcher = (
body: Get<paths[Path], [Method, "requestBody", "content", "application/json"]>
}>
): Promise<Get<paths[Path], [Method, "responses", 200, "content", "application/json"]>> => {
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;
};
};
Expand Down
5 changes: 3 additions & 2 deletions test/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ export const createBaseFetcher = (
body: Get<paths[Path], [Method, "requestBody", "content", "application/json"]>
}>
): Promise<Get<paths[Path], [Method, "responses", 200, "content", "application/json"]>> => {
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;
};
};
Expand Down

0 comments on commit 6bf8aa0

Please sign in to comment.