From 7e8f0dc3e2638ff6f8c2f43624e8b72bbb2be35f Mon Sep 17 00:00:00 2001 From: liaoxuan Date: Wed, 3 Apr 2024 17:49:18 +0800 Subject: [PATCH] fix: register global error type is not work in nextjs --- README-zh_CN.md | 2 +- README.md | 2 +- src/createInfiniteQuery.ts | 4 ++-- src/createMutation.ts | 4 ++-- src/createQuery.ts | 4 ++-- src/createSuspenseInfiniteQuery.ts | 4 ++-- src/createSuspenseQuery.ts | 4 ++-- src/router.ts | 18 ++++++++++-------- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README-zh_CN.md b/README-zh_CN.md index 5f400ff..66969d6 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -456,7 +456,7 @@ const k = { ### API 文档 -`type Router = (key: unknown | unknown[], config: TConfig) => TRouter` +`type Router = (key: string | unknown[], config: TConfig) => TRouter` Expose Methods diff --git a/README.md b/README.md index eb7b54b..985e67b 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ const k = { ### API Reference -`type Router = (key: unknown | unknown[], config: TConfig) => TRouter` +`type Router = (key: string | unknown[], config: TConfig) => TRouter` Expose Methods diff --git a/src/createInfiniteQuery.ts b/src/createInfiniteQuery.ts index e9dfca2..f79218a 100644 --- a/src/createInfiniteQuery.ts +++ b/src/createInfiniteQuery.ts @@ -6,13 +6,13 @@ import type { } from './types' import { ReactQuery } from './utils' -export const createInfiniteQuery = < +export function createInfiniteQuery< TFnData, TVariables = void, TError = CompatibleError, TPageParam = number >( options: CreateInfiniteQueryOptions -): InfiniteQueryHook => { +): InfiniteQueryHook { return createBaseQuery(options, ReactQuery.useInfiniteQuery) } diff --git a/src/createMutation.ts b/src/createMutation.ts index 7ecc155..5c17f6d 100644 --- a/src/createMutation.ts +++ b/src/createMutation.ts @@ -5,14 +5,14 @@ import type { } from './types' import { ReactQuery, withMiddleware } from './utils' -export const createMutation = < +export function createMutation< TData = unknown, TVariables = void, TError = CompatibleError, TContext = unknown >( defaultOptions: CreateMutationOptions -): MutationHook => { +): MutationHook { return Object.assign( withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'), { diff --git a/src/createQuery.ts b/src/createQuery.ts index ed563dc..01288ea 100644 --- a/src/createQuery.ts +++ b/src/createQuery.ts @@ -2,12 +2,12 @@ import { createBaseQuery } from './createBaseQuery' import type { CompatibleError, CreateQueryOptions, QueryHook } from './types' import { ReactQuery } from './utils' -export const createQuery = < +export function createQuery< TFnData, TVariables = void, TError = CompatibleError >( options: CreateQueryOptions -): QueryHook => { +): QueryHook { return createBaseQuery(options, ReactQuery.useQuery) } diff --git a/src/createSuspenseInfiniteQuery.ts b/src/createSuspenseInfiniteQuery.ts index cd5fe31..c6e6d79 100644 --- a/src/createSuspenseInfiniteQuery.ts +++ b/src/createSuspenseInfiniteQuery.ts @@ -6,7 +6,7 @@ import type { } from './types' import { ReactQuery, isV5, suspenseOptions } from './utils' -export const createSuspenseInfiniteQuery = < +export function createSuspenseInfiniteQuery< TFnData, TVariables = void, TError = CompatibleError, @@ -18,7 +18,7 @@ export const createSuspenseInfiniteQuery = < TError, TPageParam > -): SuspenseInfiniteQueryHook => { +): SuspenseInfiniteQueryHook { return isV5 ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery) : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions) diff --git a/src/createSuspenseQuery.ts b/src/createSuspenseQuery.ts index c816a36..2ff1dbd 100644 --- a/src/createSuspenseQuery.ts +++ b/src/createSuspenseQuery.ts @@ -6,13 +6,13 @@ import type { } from './types' import { ReactQuery, isV5, suspenseOptions } from './utils' -export const createSuspenseQuery = < +export function createSuspenseQuery< TFnData, TVariables = void, TError = CompatibleError >( options: CreateSuspenseQueryOptions -): SuspenseQueryHook => { +): SuspenseQueryHook { return isV5 ? createBaseQuery(options, ReactQuery.useSuspenseQuery) : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions) diff --git a/src/router.ts b/src/router.ts index 17fae15..b60d468 100644 --- a/src/router.ts +++ b/src/router.ts @@ -62,23 +62,23 @@ export const router = ( return buildRouter(Array.isArray(key) ? key : [key], config) } -router.query = ( +function query( options: RouterQueryOptions -) => { +) { return { ...options, _type: 'q', } as RouterQuery } -router.infiniteQuery = < +function infiniteQuery< TFnData, TVariables = void, TError = CompatibleError, TPageParam = number >( options: RouterInfiniteQueryOptions -) => { +) { return { ...options, _type: 'inf' } as RouterInfiniteQuery< TFnData, TVariables, @@ -87,14 +87,12 @@ router.infiniteQuery = < > } -router.mutation = < +function mutation< TFnData = unknown, TVariables = void, TError = CompatibleError, TContext = unknown ->( - options: RouterMutationOptions -) => { +>(options: RouterMutationOptions) { return { ...options, _type: 'm' } as RouterMutation< TFnData, TVariables, @@ -102,3 +100,7 @@ router.mutation = < TContext > } + +router.query = query +router.infiniteQuery = infiniteQuery +router.mutation = mutation