From ec90029388b6eda92344ce5b3057f4cdf6761ada Mon Sep 17 00:00:00 2001 From: HyunJick Lee Date: Sun, 3 Mar 2024 18:42:51 +0900 Subject: [PATCH 1/3] docs: modify typo (#7011) * docs: modify typo * docs: modify typo --- docs/framework/react/guides/prefetching.md | 2 +- docs/framework/vue/guides/prefetching.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/framework/react/guides/prefetching.md b/docs/framework/react/guides/prefetching.md index f24b46d8d6..7bb1dc4084 100644 --- a/docs/framework/react/guides/prefetching.md +++ b/docs/framework/react/guides/prefetching.md @@ -50,7 +50,7 @@ Infinite Queries can be prefetched like regular Queries. Per default, only the f [//]: # 'ExamplePrefetchInfiniteQuery' ```tsx -const prefetchTodos = async () => { +const prefetchProjects = async () => { // The results of this query will be cached like a normal query await queryClient.prefetchInfiniteQuery({ queryKey: ['projects'], diff --git a/docs/framework/vue/guides/prefetching.md b/docs/framework/vue/guides/prefetching.md index 96cb8f97e3..3946434878 100644 --- a/docs/framework/vue/guides/prefetching.md +++ b/docs/framework/vue/guides/prefetching.md @@ -30,7 +30,7 @@ Infinite Queries can be prefetched like regular Queries. Per default, only the f [//]: # 'ExampleInfiniteQuery' ```tsx -const prefetchTodos = async () => { +const prefetchProjects = async () => { // The results of this query will be cached like a normal query await queryClient.prefetchInfiniteQuery({ queryKey: ['projects'], From add26cef1b93ce880e1af0983896d54579412f3b Mon Sep 17 00:00:00 2001 From: Mahmud Zaman Bali Date: Sun, 3 Mar 2024 09:43:06 +0000 Subject: [PATCH 2/3] docs(react-query): fix typo supsends -> suspends (#6998) --- docs/framework/react/guides/advanced-ssr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/react/guides/advanced-ssr.md b/docs/framework/react/guides/advanced-ssr.md index d67503cfcf..db96d36af8 100644 --- a/docs/framework/react/guides/advanced-ssr.md +++ b/docs/framework/react/guides/advanced-ssr.md @@ -55,7 +55,7 @@ function getQueryClient() { } else { // Browser: make a new query client if we don't already have one // This is very important so we don't re-make a new client if React - // supsends during the initial render. This may not be needed if we + // suspends during the initial render. This may not be needed if we // have a suspense boundary BELOW the creation of the query client if (!browserQueryClient) browserQueryClient = makeQueryClient() return browserQueryClient From b311a0a204e91fee6a8c951ef8264353262eeb93 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Sun, 3 Mar 2024 18:43:37 +0900 Subject: [PATCH 3/3] test(solid-query): use vitest typecheck correctly with *.test-d.ts (#6986) --- .../src/__tests__/createQuery.test-d.tsx | 98 +++++++++ .../src/__tests__/createQuery.types.test.tsx | 186 ------------------ 2 files changed, 98 insertions(+), 186 deletions(-) create mode 100644 packages/solid-query/src/__tests__/createQuery.test-d.tsx delete mode 100644 packages/solid-query/src/__tests__/createQuery.types.test.tsx diff --git a/packages/solid-query/src/__tests__/createQuery.test-d.tsx b/packages/solid-query/src/__tests__/createQuery.test-d.tsx new file mode 100644 index 0000000000..5301d0c379 --- /dev/null +++ b/packages/solid-query/src/__tests__/createQuery.test-d.tsx @@ -0,0 +1,98 @@ +import { describe, expectTypeOf, it } from 'vitest' +import { createQuery, queryOptions } from '../index' + +describe('initialData', () => { + describe('Config object overload', () => { + it('TData should always be defined when initialData is provided as an object', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: { wow: true }, + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() + }) + + it('TData should be defined when passed through queryOptions', () => { + const options = queryOptions(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: { wow: true }, + })) + const { data } = createQuery(options) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() + }) + + it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: () => ({ wow: true }), + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() + }) + + it('TData should have undefined in the union when initialData is NOT provided', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() + }) + + it('TData should have undefined in the union when initialData is provided as a function which can return undefined', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: () => undefined as { wow: boolean } | undefined, + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() + }) + }) + + describe('Query key overload', () => { + it('TData should always be defined when initialData is provided', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: { wow: true }, + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() + }) + + it('TData should have undefined in the union when initialData is NOT provided', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() + }) + }) + + describe('Query key and func', () => { + it('TData should always be defined when initialData is provided', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + initialData: { wow: true }, + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() + }) + + it('TData should have undefined in the union when initialData is NOT provided', () => { + const { data } = createQuery(() => ({ + queryKey: ['key'], + queryFn: () => ({ wow: true }), + })) + + expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() + }) + }) +}) diff --git a/packages/solid-query/src/__tests__/createQuery.types.test.tsx b/packages/solid-query/src/__tests__/createQuery.types.test.tsx deleted file mode 100644 index 2bdafbc6f1..0000000000 --- a/packages/solid-query/src/__tests__/createQuery.types.test.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import { describe, it } from 'vitest' -import { createQuery, queryOptions } from '../index' - -export type Equal = (() => T extends TTargetA - ? 1 - : 2) extends () => T extends TTargetB ? 1 : 2 - ? true - : false - -export type Expect = T - -const doNotExecute = (_func: () => void) => true - -describe('initialData', () => { - describe('Config object overload', () => { - it('TData should always be defined when initialData is provided as an object', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - initialData: { - wow: true, - }, - })) - - const result: Expect> = true - return result - }) - }) - - it('TData should be defined when passed through queryOptions', () => { - doNotExecute(() => { - const options = queryOptions(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - initialData: { - wow: true, - }, - })) - const { data } = createQuery(options) - - const result: Expect> = true - return result - }) - }) - - it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - initialData: () => ({ - wow: true, - }), - })) - - const result: Expect> = true - return result - }) - }) - - it('TData should have undefined in the union when initialData is NOT provided', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - })) - - const result: Expect> = - true - return result - }) - }) - - it('TData should have undefined in the union when initialData is provided as a function which can return undefined', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - initialData: () => undefined as { wow: boolean } | undefined, - })) - - const result: Expect> = - true - return result - }) - }) - }) - - describe('Query key overload', () => { - it('TData should always be defined when initialData is provided', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - initialData: { - wow: true, - }, - })) - - const result: Expect> = true - return result - }) - }) - - it('TData should have undefined in the union when initialData is NOT provided', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - })) - - const result: Expect> = - true - return result - }) - }) - }) - - describe('Query key and func', () => { - it('TData should always be defined when initialData is provided', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - - initialData: { - wow: true, - }, - })) - - const result: Expect> = true - return result - }) - }) - - it('TData should have undefined in the union when initialData is NOT provided', () => { - doNotExecute(() => { - const { data } = createQuery(() => ({ - queryKey: ['key'], - queryFn: () => { - return { - wow: true, - } - }, - })) - - const result: Expect> = - true - return result - }) - }) - }) -})