From bbdabf544cb02c0a1077e808d09b2c3bcaa637cb Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Fri, 27 May 2022 01:10:06 -0700 Subject: [PATCH] fix: type inference bug with vueuse --- src/runtime/client.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/runtime/client.ts b/src/runtime/client.ts index 17d7de2..fe7e078 100644 --- a/src/runtime/client.ts +++ b/src/runtime/client.ts @@ -8,11 +8,12 @@ import type { import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProcedureOutput } from '@trpc/server' import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client' import { objectHash } from 'ohash' -import type { MaybeRef } from '@vueuse/core' -import { useStorage } from '@vueuse/core' +import type { Ref } from 'vue' import { useAsyncData, useNuxtApp, useState } from '#app' import type { router } from '~/server/trpc' +type MaybeRef = T | Ref + type AppRouter = typeof router export type inferProcedures< @@ -29,13 +30,6 @@ export type TError = TRPCClientErrorLike export type TQueryValues = inferProcedures -/** - * Additional header properties to pass to tRPC client. - * - * @see https://trpc.io/docs/vanilla - * @param pathAndInput tRPC client path and input. - * @param options Options to pass to useAsyncData. - */ export async function useAsyncQuery< TPath extends keyof TQueryValues & string, TOutput extends TQueryValues[TPath]['output'] = TQueryValues[TPath]['output'], @@ -68,22 +62,11 @@ export async function useAsyncQuery< } as any } -/** - * tRPC Client. - * - * @see https://trpc.io/docs/vanilla - */ export function useClient(): TRPCClient { const { $client } = useNuxtApp() return $client } -/** - * Additional header properties to pass to tRPC client. - * - * @see https://github.com/trpc/trpc/discussions/1686 - * @param initialValue - */ -export function useClientHeaders(initialValue?: MaybeRef>) { - return useStorage('trpc-nuxt-header', initialValue || {}) +export function useClientHeaders(initialValue: MaybeRef> = {}): Ref> { + return useStorage('trpc-nuxt-header', initialValue) }