|
6 | 6 | * This file should NOT be run - only type-checked. |
7 | 7 | */ |
8 | 8 | import { Elysia, t } from 'elysia' |
9 | | -import { createEdenTQ } from '../../src' |
| 9 | +import { createEdenTQ, createEdenTQUtils } from '../../src' |
10 | 10 | import { QueryClient } from '@tanstack/query-core' |
11 | 11 | import { expectTypeOf } from 'expect-type' |
12 | 12 |
|
@@ -193,3 +193,29 @@ async function testQueryClientIntegration() { |
193 | 193 | expectTypeOf<MutationResult>().not.toBeNever() |
194 | 194 | expectTypeOf<MutationResult>().toMatchTypeOf<{ id: string; name: string }>() |
195 | 195 | } |
| 196 | + |
| 197 | +// ============================================================================ |
| 198 | +// Test: EdenTQUtils methods don't become never with non-record responses |
| 199 | +// ============================================================================ |
| 200 | +{ |
| 201 | + const app = new Elysia() |
| 202 | + .get('/hello', () => ({ ok: true }), { |
| 203 | + response: t.Object({ ok: t.Boolean() }) |
| 204 | + }) |
| 205 | + .post('/echo', ({ body }) => body, { |
| 206 | + body: t.Object({ message: t.String() }), |
| 207 | + response: t.Object({ message: t.String() }) |
| 208 | + }) |
| 209 | + |
| 210 | + const eden = createEdenTQ<typeof app>('http://localhost:3000') |
| 211 | + const queryClient = new QueryClient() |
| 212 | + const utils = createEdenTQUtils(eden, queryClient) |
| 213 | + |
| 214 | + const helloOptions = utils.hello.get.queryOptions({}) |
| 215 | + type HelloData = Awaited<ReturnType<typeof helloOptions.queryFn>> |
| 216 | + expectTypeOf<HelloData>().not.toBeNever() |
| 217 | + |
| 218 | + const echoOptions = utils.echo.post.mutationOptions() |
| 219 | + type EchoResult = Awaited<ReturnType<typeof echoOptions.mutationFn>> |
| 220 | + expectTypeOf<EchoResult>().not.toBeNever() |
| 221 | +} |
0 commit comments