Skip to content

Commit bea4b02

Browse files
committed
minor fix to optional var types
1 parent fd54d48 commit bea4b02

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

examples/vite/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const baseMutation = baseQuery.asMutationBuilder();
2121

2222
const resetMutation = baseMutation.withPath('/reset').withUpdates('*');
2323

24-
const postsQuery = baseQuery.withTags('refreshable', 'posts').withPath('/posts').withData<PostData[]>();
24+
const postsQuery = baseQuery.withTags('refreshable', 'posts').withPath('/posts').withData<PostData[]>().withSearch<{ page?: number }>();
2525

2626
const postQuery = baseQuery
2727
.withTags('refreshable')
@@ -62,7 +62,7 @@ const editPostMutation = baseMutation
6262
...ctx,
6363
vars: {
6464
...ctx.vars,
65-
body: { ...ctx.vars.body, body: `${ctx.vars.body.body} \n Last updated ${new Date().toISOString()}` },
65+
body: { ...ctx.vars.body, body: `${ctx.vars.body?.body} \n Last updated ${new Date().toISOString()}` },
6666
},
6767
});
6868
return res;

examples/vite/src/mocks/mocks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ const handlers = [
6868
await delay();
6969
return HttpResponse.json(users);
7070
}),
71-
http.get(`${baseUrl}/posts`, async () => {
71+
http.get(`${baseUrl}/posts`, async (req) => {
7272
await delay();
73-
return HttpResponse.json(posts);
73+
const page = Number(new URL(req.request.url).searchParams.get('page')) || 0;
74+
const pageSize = 5;
75+
return HttpResponse.json(posts.slice(page * pageSize, (page + 1) * pageSize));
7476
}),
7577
http.get(`${baseUrl}/posts/:id`, async (req) => {
7678
await delay();

src/builder/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ type WhenRequired<T, TReq> = T extends undefined
2424
? Partial<TReq>
2525
: T extends null
2626
? Partial<TReq>
27-
: TReq;
27+
: Partial<T> extends T
28+
? Partial<TReq>
29+
: TReq;
2830

2931
export type HttpBuilderVars<TParam = unknown, TSearch = unknown, TBody = unknown, THeaders = unknown, TMeta = unknown> = Prettify<
3032
HttpBuilderBaseVars &

src/tags/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type PredefinedUpdater<TVars = unknown, TData = unknown, TErr = unknown,
4444
| `replace-${UpdaterSelector<TVars>}`
4545
| `${'create' | 'update' | 'upsert' | 'delete' | 'switch'}-${UpdaterSelector<TVars>}-by-${KeyOfTarget<TTarget>}`;
4646

47-
type UpdaterSelector<TVars> = 'data' | 'vars' | Extract<KeysOfValue<TVars, Record<string, unknown>>, string>;
47+
type UpdaterSelector<TVars> = 'data' | 'vars' | Extract<KeysOfValue<TVars, Record<string, unknown> | undefined>, string>;
4848
type KeyOfTarget<TTarget> = KeyOfItem<TTarget> & string & {};
4949
type KeyOfItem<TTarget> = TTarget extends readonly (infer TItem)[]
5050
? keyof TItem

src/types/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export type FunctionType = (...args: any[]) => any;
1616

1717
/** Extracts the keys of a type that have a value of a specific type. */
1818
export type KeysOfValue<T, TCondition> = {
19-
[K in keyof T]?: T[K] extends TCondition ? K : never;
19+
[K in keyof T]: T[K] extends TCondition ? K : never;
2020
}[keyof T];

0 commit comments

Comments
 (0)