refactor: 统一客户端类型定义并增强类型一致性
- 更新客户端类型以使用定义的 APIClient 类型并确保类型一致性 - 添加类型定义以导出基于路由配置的客户端类型。
This commit is contained in:
@@ -5,6 +5,7 @@ import { createTanstackQueryUtils } from '@orpc/tanstack-query'
|
||||
import { createIsomorphicFn } from '@tanstack/react-start'
|
||||
import { getRequestHeaders } from '@tanstack/react-start/server'
|
||||
import { router } from './router'
|
||||
import type { APIClient } from './types'
|
||||
|
||||
const getORPCClient = createIsomorphicFn()
|
||||
.server(() =>
|
||||
@@ -18,9 +19,9 @@ const getORPCClient = createIsomorphicFn()
|
||||
const link = new RPCLink({
|
||||
url: `${window.location.origin}/api/rpc`,
|
||||
})
|
||||
return createORPCClient<RouterClient<typeof router>>(link)
|
||||
return createORPCClient<APIClient>(link)
|
||||
})
|
||||
|
||||
const client = getORPCClient()
|
||||
const client: APIClient = getORPCClient()
|
||||
|
||||
export const orpc = createTanstackQueryUtils(client)
|
||||
|
||||
4
src/orpc/types.ts
Normal file
4
src/orpc/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { RouterClient } from '@orpc/server'
|
||||
import type { router } from './router'
|
||||
|
||||
export type APIClient = RouterClient<typeof router>
|
||||
Reference in New Issue
Block a user