Skip to content

[Feature Request] [Low Effort] Add trpc client types for trpc-nuxt #1703

@juni0r

Description

@juni0r

Currently the @zenstackhq/trpc plugin only generates client types for React and Next clients. The types for the Nuxt client trpc-nuxt would be a welcome addition.

It's quite trivial to derive from the Next client and would just require a slightly modified generator template.

Here's the modified version I'm actually using, which is analogous to the Next client:

import type { AnyRouter } from '@trpc/server'
import { createTRPCNuxtClient as _createTRPCNuxtClient } from 'trpc-nuxt/client'
import type { ClientType } from '../routers'
import type { DeepOverrideAtPath } from './utils'

type TRPCNuxtClient<TRouter extends AnyRouter> = ReturnType<typeof _createTRPCNuxtClient<TRouter>>

export function createTRPCNuxtClient<
  TRouter extends AnyRouter,
  TPath extends string | undefined = undefined,
>(...args: Parameters<typeof _createTRPCNuxtClient<TRouter>>) {
  const r: TRPCNuxtClient<TRouter> = _createTRPCNuxtClient<TRouter>(...args)
  return r as DeepOverrideAtPath<TRPCNuxtClient<TRouter>, ClientType<TRouter>, TPath>
}

Would be great if this could make it into the plugin!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions