Skip to content

Commit de74b2e

Browse files
committed
test(vue-query): cover nested refs in branded objects
1 parent 4e8e318 commit de74b2e

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎packages/vue-query/src/__tests__/queryOptions.test-d.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { queryKey } from '@tanstack/query-test-utils'
55
import { QueryClient } from '../queryClient'
66
import { queryOptions } from '../queryOptions'
77
import { useQuery } from '../useQuery'
8+
import type { MaybeRefDeep } from '../types'
89

910
// Regression test for exported queryOptions inference under declaration emit.
1011
// TypeScript should be able to name the return type without expanding the
@@ -403,17 +404,18 @@ describe('queryOptions', () => {
403404
}),
404405
)
405406
expectTypeOf(inlineData).toEqualTypeOf<{ id: PostId } | undefined>()
407+
})
406408

407-
const brandedObjectOptions = queryOptions({
408-
queryKey: [
409-
'post',
410-
{ __brand: 'post' as const, postId: ref('123') },
411-
] as const,
412-
queryFn: () => Promise.resolve({ id: postId }),
413-
})
414-
const { data: brandedObjectData } = reactive(useQuery(brandedObjectOptions))
415-
expectTypeOf(brandedObjectData).toEqualTypeOf<{ id: PostId } | undefined>()
416-
expectTypeOf(brandedObjectOptions.queryKey[1].postId).toMatchTypeOf<
409+
it('should recursively unwrap objects with a __brand property', () => {
410+
const options = {
411+
__brand: 'post' as const,
412+
postId: ref('123'),
413+
} satisfies MaybeRefDeep<{
414+
__brand: 'post'
415+
postId: string
416+
}>
417+
418+
expectTypeOf(options.postId).toMatchTypeOf<
417419
string | ReturnType<typeof ref>
418420
>()
419421
})

0 commit comments

Comments
 (0)