Skip to content

Commit 30fc3c7

Browse files
committed
Fix typing issue
1 parent d6c110a commit 30fc3c7

File tree

8 files changed

+202
-92
lines changed

8 files changed

+202
-92
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"packages/generator/package.json":"Patch"},"note":"Fix gen issue","date":"2025-12-04T13:14:14.424512200Z"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"packages/core/package.json":"Patch","packages/react-query/package.json":"Patch","packages/fetch/package.json":"Patch"},"note":"Fix query typing issue","date":"2025-12-04T13:14:26.431881700Z"}

examples/next/app/page.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ const api2 = createApi({
1616
const queryClient = createQueryClient(api)
1717

1818
export default function Home() {
19-
const { data, isLoading, error } = queryClient.useQuery(
20-
'GET',
21-
'getUserById',
22-
{
23-
params: { id: 1 },
24-
query: {
25-
name: 'John Doe',
26-
},
19+
const { data, isLoading, error } = queryClient.useQuery('GET', 'getUsers', {
20+
// params: { id: 1 },
21+
query: {
22+
name: 'John Doe',
2723
},
28-
)
24+
})
2925

3026
console.info(data, isLoading, error)
3127

3228
const {
3329
data: data2,
34-
isLoading: isLoading2,
3530
error: error2,
36-
} = queryClient.useQuery('GET', '/users', {
31+
mutateAsync,
32+
} = queryClient.useMutation('GET', '/users/{id}', {})
33+
mutateAsync({
3734
params: { id: 1 },
35+
query: {
36+
name: 'John Doe',
37+
},
3838
})
3939

40-
console.info(data2, isLoading2, error2)
40+
console.info(data2, error2)
4141

4242
useEffect(() => {
4343
api2.get('getUsers2').then((res) => {
4444
console.log(res)
4545
})
46-
api.get('getUsers').then((res) => {
46+
api.get('getUsers', {}).then((res) => {
4747
console.log(res)
4848
})
4949

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"lint": "biome check",
1919
"lint:fix": "biome check --write",
2020
"prepare": "husky",
21-
"build": "bun run -F @devup-api/core build && bun run -F @devup-api/utils build && bun run -F @devup-api/generator build && bun run -F @devup-api/fetch build && bun run -F @devup-api/webpack-plugin build && bun run -F @devup-api/vite-plugin build && bun run -F @devup-api/next-plugin build && bun run -F @devup-api/rsbuild-plugin build",
22-
"publish": "bun publish --cwd packages/core && bun publish --cwd packages/utils && bun publish --cwd packages/generator && bun publish --cwd packages/fetch && bun publish --cwd packages/webpack-plugin && bun publish --cwd packages/vite-plugin && bun publish --cwd packages/next-plugin && bun publish --cwd packages/rsbuild-plugin"
21+
"build": "bun run -F @devup-api/core build && bun run -F @devup-api/utils build && bun run -F @devup-api/generator build && bun run -F @devup-api/fetch build && bun run -F @devup-api/webpack-plugin build && bun run -F @devup-api/vite-plugin build && bun run -F @devup-api/next-plugin build && bun run -F @devup-api/rsbuild-plugin build && bun run -F @devup-api/react-query build",
22+
"publish": "bun publish --cwd packages/core && bun publish --cwd packages/utils && bun publish --cwd packages/generator && bun publish --cwd packages/fetch && bun publish --cwd packages/webpack-plugin && bun publish --cwd packages/vite-plugin && bun publish --cwd packages/next-plugin && bun publish --cwd packages/rsbuild-plugin && bun publish --cwd packages/react-query"
2323
},
2424
"workspaces": [
2525
"packages/*",

packages/core/src/additional.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DevupApiServers } from './api-struct'
12
import type { Middleware } from './middleware'
23

34
export type Additional<
@@ -14,6 +15,7 @@ export type RequiredOptions<T extends object> = keyof T extends undefined
1415
: 'body' extends keyof T
1516
? T
1617
: never
18+
export type IsCold = keyof DevupApiServers extends never ? true : false
1719
export type DevupApiRequestInit = Omit<RequestInit, 'body'> & {
1820
body?: object | RequestInit['body']
1921
params?: Record<string, string | number | boolean | null | undefined>

packages/fetch/src/api.ts

Lines changed: 116 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
DevupPutApiStructKey,
1717
DevupPutApiStructScope,
1818
ExtractValue,
19+
IsCold,
1920
Middleware,
2021
RequiredOptions,
2122
} from '@devup-api/core'
@@ -59,8 +60,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
5960
>(
6061
path: T,
6162
...options: [RequiredOptions<O>] extends [never]
62-
? [options?: DevupApiRequestInit]
63-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
63+
? [
64+
options?: IsCold extends true
65+
? DevupApiRequestInit
66+
: Omit<DevupApiRequestInit, 'params'> &
67+
Omit<O, 'response' | 'error'>,
68+
]
69+
: [
70+
options: Omit<DevupApiRequestInit, 'params'> &
71+
Omit<O, 'response' | 'error'>,
72+
]
6473
): Promise<
6574
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
6675
> {
@@ -76,8 +85,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
7685
>(
7786
path: T,
7887
...options: [RequiredOptions<O>] extends [never]
79-
? [options?: DevupApiRequestInit]
80-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
88+
? [
89+
options?: IsCold extends true
90+
? DevupApiRequestInit
91+
: Omit<DevupApiRequestInit, 'params'> &
92+
Omit<O, 'response' | 'error'>,
93+
]
94+
: [
95+
options: Omit<DevupApiRequestInit, 'params'> &
96+
Omit<O, 'response' | 'error'>,
97+
]
8198
): Promise<
8299
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
83100
> {
@@ -93,8 +110,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
93110
>(
94111
path: T,
95112
...options: [RequiredOptions<O>] extends [never]
96-
? [options?: DevupApiRequestInit]
97-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
113+
? [
114+
options?: IsCold extends true
115+
? DevupApiRequestInit
116+
: Omit<DevupApiRequestInit, 'params'> &
117+
Omit<O, 'response' | 'error'>,
118+
]
119+
: [
120+
options: Omit<DevupApiRequestInit, 'params'> &
121+
Omit<O, 'response' | 'error'>,
122+
]
98123
): Promise<
99124
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
100125
> {
@@ -110,8 +135,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
110135
>(
111136
path: T,
112137
...options: [RequiredOptions<O>] extends [never]
113-
? [options?: DevupApiRequestInit]
114-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
138+
? [
139+
options?: IsCold extends true
140+
? DevupApiRequestInit
141+
: Omit<DevupApiRequestInit, 'params'> &
142+
Omit<O, 'response' | 'error'>,
143+
]
144+
: [
145+
options: Omit<DevupApiRequestInit, 'params'> &
146+
Omit<O, 'response' | 'error'>,
147+
]
115148
): Promise<
116149
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
117150
> {
@@ -127,8 +160,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
127160
>(
128161
path: T,
129162
...options: [RequiredOptions<O>] extends [never]
130-
? [options?: DevupApiRequestInit]
131-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
163+
? [
164+
options?: IsCold extends true
165+
? DevupApiRequestInit
166+
: Omit<DevupApiRequestInit, 'params'> &
167+
Omit<O, 'response' | 'error'>,
168+
]
169+
: [
170+
options: Omit<DevupApiRequestInit, 'params'> &
171+
Omit<O, 'response' | 'error'>,
172+
]
132173
): Promise<
133174
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
134175
> {
@@ -144,8 +185,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
144185
>(
145186
path: T,
146187
...options: [RequiredOptions<O>] extends [never]
147-
? [options?: DevupApiRequestInit]
148-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
188+
? [
189+
options?: IsCold extends true
190+
? DevupApiRequestInit
191+
: Omit<DevupApiRequestInit, 'params'> &
192+
Omit<O, 'response' | 'error'>,
193+
]
194+
: [
195+
options: Omit<DevupApiRequestInit, 'params'> &
196+
Omit<O, 'response' | 'error'>,
197+
]
149198
): Promise<
150199
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
151200
> {
@@ -161,8 +210,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
161210
>(
162211
path: T,
163212
...options: [RequiredOptions<O>] extends [never]
164-
? [options?: DevupApiRequestInit]
165-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
213+
? [
214+
options?: IsCold extends true
215+
? DevupApiRequestInit
216+
: Omit<DevupApiRequestInit, 'params'> &
217+
Omit<O, 'response' | 'error'>,
218+
]
219+
: [
220+
options: Omit<DevupApiRequestInit, 'params'> &
221+
Omit<O, 'response' | 'error'>,
222+
]
166223
): Promise<
167224
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
168225
> {
@@ -178,8 +235,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
178235
>(
179236
path: T,
180237
...options: [RequiredOptions<O>] extends [never]
181-
? [options?: DevupApiRequestInit]
182-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
238+
? [
239+
options?: IsCold extends true
240+
? DevupApiRequestInit
241+
: Omit<DevupApiRequestInit, 'params'> &
242+
Omit<O, 'response' | 'error'>,
243+
]
244+
: [
245+
options: Omit<DevupApiRequestInit, 'params'> &
246+
Omit<O, 'response' | 'error'>,
247+
]
183248
): Promise<
184249
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
185250
> {
@@ -195,8 +260,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
195260
>(
196261
path: T,
197262
...options: [RequiredOptions<O>] extends [never]
198-
? [options?: DevupApiRequestInit]
199-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
263+
? [
264+
options?: IsCold extends true
265+
? DevupApiRequestInit
266+
: Omit<DevupApiRequestInit, 'params'> &
267+
Omit<O, 'response' | 'error'>,
268+
]
269+
: [
270+
options: Omit<DevupApiRequestInit, 'params'> &
271+
Omit<O, 'response' | 'error'>,
272+
]
200273
): Promise<
201274
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
202275
> {
@@ -212,8 +285,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
212285
>(
213286
path: T,
214287
...options: [RequiredOptions<O>] extends [never]
215-
? [options?: DevupApiRequestInit]
216-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
288+
? [
289+
options?: IsCold extends true
290+
? DevupApiRequestInit
291+
: Omit<DevupApiRequestInit, 'params'> &
292+
Omit<O, 'response' | 'error'>,
293+
]
294+
: [
295+
options: Omit<DevupApiRequestInit, 'params'> &
296+
Omit<O, 'response' | 'error'>,
297+
]
217298
): Promise<
218299
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
219300
> {
@@ -229,8 +310,16 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
229310
>(
230311
path: T,
231312
...options: [RequiredOptions<O>] extends [never]
232-
? [options?: DevupApiRequestInit]
233-
: [options: DevupApiRequestInit & Omit<O, 'response' | 'error'>]
313+
? [
314+
options?: IsCold extends true
315+
? DevupApiRequestInit
316+
: Omit<DevupApiRequestInit, 'params'> &
317+
Omit<O, 'response' | 'error'>,
318+
]
319+
: [
320+
options: Omit<DevupApiRequestInit, 'params'> &
321+
Omit<O, 'response' | 'error'>,
322+
]
234323
): Promise<
235324
DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
236325
> {
@@ -242,7 +331,7 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
242331
body,
243332
params,
244333
...restOptions
245-
} = options[0] || {}
334+
}: DevupApiRequestInit = options[0] || {}
246335
const mergedHeaders = new Headers(headers)
247336
const mergedOptions = {
248337
...this.defaultOptions,
@@ -354,19 +443,19 @@ export class DevupApi<S extends ConditionalKeys<DevupApiServers>> {
354443
} as DevupApiResponse<ExtractValue<O, 'response'>, ExtractValue<O, 'error'>>
355444
}
356445

357-
setDefaultOptions(options: DevupApiRequestInit) {
446+
setDefaultOptions(options: DevupApiRequestInit): void {
358447
this.defaultOptions = options
359448
}
360449

361-
getBaseUrl() {
450+
getBaseUrl(): string {
362451
return this.baseUrl
363452
}
364453

365-
getDefaultOptions() {
454+
getDefaultOptions(): DevupApiRequestInit {
366455
return this.defaultOptions
367456
}
368457

369-
use(...middleware: Middleware[]) {
458+
use(...middleware: Middleware[]): void {
370459
this.middleware.push(...middleware)
371460
}
372461
}

packages/react-query/src/__tests__/query-client.test.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ test('DevupQueryClient useInfiniteQuery with GET method', async () => {
206206

207207
const { result } = renderHook(
208208
() =>
209-
queryClient.useInfiniteQuery('get', '/test' as any, undefined, {
209+
queryClient.useInfiniteQuery('get', '/test' as any, {
210210
initialPageParam: 1,
211211
getNextPageParam: () => undefined,
212212
}),
@@ -232,17 +232,11 @@ test('DevupQueryClient useInfiniteQuery with options', async () => {
232232

233233
const { result } = renderHook(
234234
() =>
235-
queryClient.useInfiniteQuery(
236-
'get',
237-
'/test' as any,
238-
{
239-
query: { page: 1 },
240-
},
241-
{
242-
initialPageParam: 1,
243-
getNextPageParam: () => undefined,
244-
},
245-
),
235+
queryClient.useInfiniteQuery('get', '/test' as any, {
236+
initialPageParam: 1,
237+
getNextPageParam: () => undefined,
238+
query: { page: 1 },
239+
}),
246240
{ wrapper: createWrapper() },
247241
)
248242

@@ -267,7 +261,7 @@ test('DevupQueryClient useQuery with different HTTP methods', async () => {
267261

268262
for (const method of methods) {
269263
const { result } = renderHook(
270-
() => queryClient.useQuery(method as any, '/test' as any),
264+
() => queryClient.useQuery(method as any, '/test' as any, {}),
271265
{ wrapper: createWrapper() },
272266
)
273267

@@ -317,7 +311,7 @@ test('DevupQueryClient useSuspenseQuery with different HTTP methods', async () =
317311

318312
for (const method of methods) {
319313
const { result } = renderHook(
320-
() => queryClient.useSuspenseQuery(method as any, '/test' as any),
314+
() => queryClient.useSuspenseQuery(method as any, '/test' as any, {}),
321315
{ wrapper: createWrapper() },
322316
)
323317

@@ -341,7 +335,7 @@ test('DevupQueryClient useInfiniteQuery with different HTTP methods', async () =
341335
for (const method of methods) {
342336
const { result } = renderHook(
343337
() =>
344-
queryClient.useInfiniteQuery(method as any, '/test' as any, undefined, {
338+
queryClient.useInfiniteQuery(method as any, '/test' as any, {
345339
initialPageParam: 1,
346340
getNextPageParam: () => undefined,
347341
}),

0 commit comments

Comments
 (0)