refactor: 简化客户端类型声明并增强路由客户端类型支持

- 更新客户端类型推断并简化类型声明以支持更灵活的路由客户端使用
- 导出路由器客户端类型以支持类型安全的客户端调用。
This commit is contained in:
2026-01-18 02:25:14 +08:00
parent 728aeac32c
commit 46c370a5a8
2 changed files with 7 additions and 5 deletions

View File

@@ -1,11 +1,10 @@
import { createORPCClient } from '@orpc/client'
import { RPCLink } from '@orpc/client/fetch'
import type { RouterClient } from '@orpc/server'
import { createRouterClient } from '@orpc/server'
import { createTanstackQueryUtils } from '@orpc/tanstack-query'
import { createIsomorphicFn } from '@tanstack/react-start'
import { getRequestHeaders } from '@tanstack/react-start/server'
import { router } from '@/orpc/router'
import { type RouterClient, router } from '@/orpc'
const getORPCClient = createIsomorphicFn()
.server(() =>
@@ -15,13 +14,13 @@ const getORPCClient = createIsomorphicFn()
}),
}),
)
.client((): RouterClient<typeof router> => {
.client(() => {
const link = new RPCLink({
url: `${window.location.origin}/api/rpc`,
})
return createORPCClient(link)
return createORPCClient<RouterClient>(link)
})
const client: RouterClient<typeof router> = getORPCClient()
const client: RouterClient = getORPCClient()
export const orpc = createTanstackQueryUtils(client)

View File

@@ -1,5 +1,8 @@
import type { RouterClient as ORPCRouterClient } from '@orpc/server'
import * as todo from './handlers/todo'
export const router = {
todo,
}
export type RouterClient = ORPCRouterClient<typeof router>