mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
refactor: type helpers
This commit is contained in:
@@ -143,6 +143,7 @@ export const onError = (payload: OnErrorPayload<typeof router>) => {
|
||||
- [Merging Routers](/recipes/merging-routers.md)
|
||||
- [Error Handling](/recipes/error-handling.md)
|
||||
- [Error Formatting](/recipes/error-formatting.md)
|
||||
- [Inference Helpers](/recipes/inference-helpers.md)
|
||||
|
||||
Learn more about tRPC.io [here](https://trpc.io/docs).
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
},
|
||||
async setup(options, nuxt) {
|
||||
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
||||
nuxt.options.build.transpile.push(runtimeDir, '#build/trpc-client', '#build/trpc-handler')
|
||||
nuxt.options.build.transpile.push(runtimeDir, '#build/trpc-client', '#build/trpc-handler', '#build/trpc-helpers')
|
||||
|
||||
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
|
||||
const trpcOptionsPath = join(nuxt.options.rootDir, 'server/trpc')
|
||||
@@ -82,7 +82,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
addTemplate({
|
||||
filename: 'trpc-helpers.ts',
|
||||
write: true,
|
||||
src: join(runtimeDir, 'helpers.ts'),
|
||||
src: join(runtimeDir, 'helpers.d.ts'),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -10,11 +10,12 @@ import type { TRPCClientErrorLike } from '@trpc/client'
|
||||
import { objectHash } from 'ohash'
|
||||
import { useAsyncData, useState } from '#app'
|
||||
import { useClient } from '#build/trpc-client'
|
||||
// @ts-expect-error: Resolved by Nuxt
|
||||
import type { router } from '~/server/trpc'
|
||||
|
||||
type AppRouter = typeof router
|
||||
|
||||
type inferProcedures<
|
||||
export type inferProcedures<
|
||||
TObj extends ProcedureRecord<any, any, any, any, any, any>,
|
||||
> = {
|
||||
[TPath in keyof TObj]: {
|
||||
@@ -23,10 +24,10 @@ type inferProcedures<
|
||||
};
|
||||
}
|
||||
|
||||
type TQueries = AppRouter['_def']['queries']
|
||||
type TError = TRPCClientErrorLike<AppRouter>
|
||||
export type TQueries = AppRouter['_def']['queries']
|
||||
export type TError = TRPCClientErrorLike<AppRouter>
|
||||
|
||||
type TQueryValues = inferProcedures<AppRouter['_def']['queries']>
|
||||
export type TQueryValues = inferProcedures<AppRouter['_def']['queries']>
|
||||
|
||||
export async function useAsyncQuery<
|
||||
TPath extends keyof TQueryValues & string,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server'
|
||||
// @ts-expect-error: Resolved by Nuxt
|
||||
import type { router } from '~/server/trpc'
|
||||
|
||||
/**
|
||||
* The main router type
|
||||
*/
|
||||
export type AppRouter = typeof router
|
||||
type AppRouter = typeof router
|
||||
|
||||
/**
|
||||
* Enum containing all api query paths
|
||||
Reference in New Issue
Block a user