Skip to content

Commit

Permalink
fix: register global error type is not work in nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoxuan committed Apr 3, 2024
1 parent 7d591df commit 7e8f0dc
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/createInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFnData, TVariables, TError, TPageParam>
): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {
): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {
return createBaseQuery(options, ReactQuery.useInfiniteQuery)
}
4 changes: 2 additions & 2 deletions src/createMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData, TVariables, TError, TContext>
): MutationHook<TData, TVariables, TError, TContext> => {
): MutationHook<TData, TVariables, TError, TContext> {
return Object.assign(
withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),
{
Expand Down
4 changes: 2 additions & 2 deletions src/createQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFnData, TVariables, TError>
): QueryHook<TFnData, TVariables, TError> => {
): QueryHook<TFnData, TVariables, TError> {
return createBaseQuery(options, ReactQuery.useQuery)
}
4 changes: 2 additions & 2 deletions src/createSuspenseInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +18,7 @@ export const createSuspenseInfiniteQuery = <
TError,
TPageParam
>
): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {
): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {
return isV5
? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)
: createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)
Expand Down
4 changes: 2 additions & 2 deletions src/createSuspenseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFnData, TVariables, TError>
): SuspenseQueryHook<TFnData, TVariables, TError> => {
): SuspenseQueryHook<TFnData, TVariables, TError> {
return isV5
? createBaseQuery(options, ReactQuery.useSuspenseQuery)
: createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)
Expand Down
18 changes: 10 additions & 8 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ export const router = <TConfig extends RouterConfig>(
return buildRouter(Array.isArray(key) ? key : [key], config)
}

router.query = <TFnData, TVariables = void, TError = CompatibleError>(
function query<TFnData, TVariables = void, TError = CompatibleError>(
options: RouterQueryOptions<TFnData, TVariables, TError>
) => {
) {
return {
...options,
_type: 'q',
} as RouterQuery<TFnData, TVariables, TError>
}

router.infiniteQuery = <
function infiniteQuery<
TFnData,
TVariables = void,
TError = CompatibleError,
TPageParam = number
>(
options: RouterInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
) => {
) {
return { ...options, _type: 'inf' } as RouterInfiniteQuery<
TFnData,
TVariables,
Expand All @@ -87,18 +87,20 @@ router.infiniteQuery = <
>
}

router.mutation = <
function mutation<
TFnData = unknown,
TVariables = void,
TError = CompatibleError,
TContext = unknown
>(
options: RouterMutationOptions<TFnData, TVariables, TError, TContext>
) => {
>(options: RouterMutationOptions<TFnData, TVariables, TError, TContext>) {
return { ...options, _type: 'm' } as RouterMutation<
TFnData,
TVariables,
TError,
TContext
>
}

router.query = query
router.infiniteQuery = infiniteQuery
router.mutation = mutation

0 comments on commit 7e8f0dc

Please sign in to comment.