mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-04-09 05:50:06 +08:00
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
// Src/utils/trpc.ts
|
|
import { createReactQueryHooks } from '@trpc/react';
|
|
import type { inferProcedureInput, inferProcedureOutput } from '@trpc/server';
|
|
|
|
import type { AppRouter } from '~/server/router';
|
|
|
|
export const trpc = createReactQueryHooks<AppRouter>();
|
|
|
|
/**
|
|
* These are helper types to infer the input and output of query resolvers
|
|
* @example type HelloOutput = inferQueryOutput<'hello'>
|
|
*/
|
|
export type inferQueryOutput<
|
|
TRouteKey extends keyof AppRouter['_def']['queries'],
|
|
> = inferProcedureOutput<AppRouter['_def']['queries'][TRouteKey]>;
|
|
|
|
export type inferQueryInput<
|
|
TRouteKey extends keyof AppRouter['_def']['queries'],
|
|
> = inferProcedureInput<AppRouter['_def']['queries'][TRouteKey]>;
|
|
|
|
export type inferMutationOutput<
|
|
TRouteKey extends keyof AppRouter['_def']['mutations'],
|
|
> = inferProcedureOutput<AppRouter['_def']['mutations'][TRouteKey]>;
|
|
|
|
export type inferMutationInput<
|
|
TRouteKey extends keyof AppRouter['_def']['mutations'],
|
|
> = inferProcedureInput<AppRouter['_def']['mutations'][TRouteKey]>;
|