Skip to content

Commit 270e3fd

Browse files
Frank-IIIAmp
andcommitted
Add EdenTQUtils fallback type test
Amp-Thread-ID: https://ampcode.com/threads/T-019c1fb5-9bdc-716e-aee6-e3391dd495c3 Co-authored-by: Amp <amp@ampcode.com>
1 parent 3bbba99 commit 270e3fd

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

test/types/extract-data-fallback.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This file should NOT be run - only type-checked.
77
*/
88
import { Elysia, t } from 'elysia'
9-
import { createEdenTQ } from '../../src'
9+
import { createEdenTQ, createEdenTQUtils } from '../../src'
1010
import { QueryClient } from '@tanstack/query-core'
1111
import { expectTypeOf } from 'expect-type'
1212

@@ -193,3 +193,29 @@ async function testQueryClientIntegration() {
193193
expectTypeOf<MutationResult>().not.toBeNever()
194194
expectTypeOf<MutationResult>().toMatchTypeOf<{ id: string; name: string }>()
195195
}
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

Comments
 (0)