मुख्य सामग्री पर जाएँ
Skillpedia
API और सर्वर (backend)12k · #11521

nestjs-trpc

यह क्या करती है

यह AI को tRPC राउटर को NestJS क्लास के रूप में परिभाषित करने, Zod स्कीमा जोड़ने और क्लाइंट का टाइप बनाने के चरण समझाती है। यह NestJS में end-to-end टाइप सुरक्षा चाहने वाले डेवलपर्स के लिए है।

कब इस्तेमाल करें

  • ✓जब आप NestJS ऐप के अंदर tRPC प्रोसीजर चाहते हैं।
  • ✓जब आप NestJS प्रोजेक्ट में @Router, @Query या @Mutation डेकोरेटर इस्तेमाल करते हैं।
  • ✓जब आपके क्लाइंट में कोई टाइप न हो या AppRouter टाइप पुराना हो।

Skill का लिंक

https://github.com/trycompai/crm/blob/release/.agents/skills/nestjs-trpc/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/trycompai/crm/blob/release/.agents/skills/nestjs-trpc/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“क्या आप मेरे NestJS ऐप में tRPC क्वेरी जोड़ सकते हैं, जो id से यूज़र लौटाए और उसका इनपुट Zod स्कीमा से जाँचे?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

AI decorated राउटर क्लास सेट करता है, उसे NestJS मॉड्यूल में रजिस्टर करता है और CLI चलाता है ताकि क्लाइंट को मेल खाता AppRouter टाइप मिले।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

NestJS-tRPC

nestjs-trpc lets you define tRPC procedures as decorated NestJS classes instead of chaining t.procedure builders. Routers are DI-aware classes that look like controllers; a separate CLI reads those decorators and emits an AppRouter type for the client.

Verified against v2.13.0. The published docs at nestjs-trpc.io still contain v1-era examples in several places. Where this skill and the docs disagree, this skill matches the shipped .d.ts files and the official examples/ in the repo — see Docs errata for the specific traps.

The one thing to internalize

There are two separate systems that both need to be correct, and they fail independently:

Runtime Type generation
Driven by Nest DI container at boot Rust CLI doing static analysis of your source
Needs classes listed in providers decorators it can read literally
Fails as 404 / "no procedures" / undefined injection stale or missing AppRouter

A router that works at runtime but was never picked up by the CLI produces a client with no types, and vice versa. When something is wrong, first ask which of the two is broken.

Setup workflow

1. Install

npm install nestjs-trpc zod @trpc/server

Peer deps (v2.13.0): @nestjs/common & @nestjs/core ^9.3.8 || ^10 || ^11, @trpc/server ^11, zod ^3.14 || ^4, rxjs 7.8.1, reflect-metadata ^0.1.13 || ^0.2. tRPC v11 is required — v10 will not work.

Standard NestJS tsconfig.json requirements apply: experimentalDecorators: true, emitDecoratorMetadata: true. tsc must be resolvable, because the CLI shells out to it to typecheck what it generates.

2. Register the module

// app.module.ts
import { Module } from '@nestjs/common';
import { TRPCModule } from 'nestjs-trpc';
import { UserRouter } from './user.router';
import { UserService } from './user.service';
import { ProtectedMiddleware } from './protected.middleware';
import { AppContext } from './app.context';

@Module({
  imports: [
    TRPCModule.forRoot({
      context: AppContext,
    }),
  ],
  providers: [UserRouter, AppContext, UserService, ProtectedMiddleware],
})
export class AppModule {}

Routers, middlewares, and the context class are all ordinary providers. Listing them in providers is what makes DI work — forgetting a router here is the single most common reason procedures silently don't exist at runtime.

Default mount point is /trpc; override with basePath. Full option table in references/module-config.md.

3. Write a router

// user.router.ts
import { Inject } from '@nestjs/common';
import { Router, Query, Mutation, UseMiddlewares, Input, Ctx } from 'nestjs-trpc';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { UserService } from './user.service';
import { ProtectedMiddleware } from './protected.middleware';
import { userSchema, type User } from './user.schema';

@Router({ alias: 'users' })
export class UserRouter {
  constructor(@Inject(UserService) private readonly userService: UserService) {}

  @Query({
    input: z.object({ userId: z.string() }),
    output: userSchema,
  })
  @UseMiddlewares(ProtectedMiddleware)
  async getUserById(@Input('userId') userId: string): Promise<User> {
    const user = await this.userService.getUser(userId);

    if (user == null) {
      throw new TRPCError({ message: 'Could not find user.', code: 'NOT_FOUND' });
    }

    return user;
  }
}

Client call site: trpc.users.getUserById.query({ userId }). The alias sets that first segment — without it the class name is used.

4. Generate the client type

npx nestjs-trpc generate      # one-shot
npx nestjs-trpc watch         # regenerate on change during development

Writes server.ts (containing export type AppRouter = typeof appRouter) to ./src/@generated by default; --output <dir> moves it. This is a build step, not a runtime import — the generated file is types only, and your procedures still execute through the Nest-managed router at runtime.

Add it to your scripts so it can't drift:

{
  "scripts": {
    "dev": "nestjs-trpc watch & nest start --watch",
    "build": "nestjs-trpc generate && nest build"
  }
}

Run nestjs-trpc generate --dry-run in CI to fail the build when the committed types are stale.

Writing procedures

Three procedure decorators, all taking `{ input?, output?,

अक्सर पूछे जाने वाले सवाल

क्लाइंट में टाइप क्यों नहीं हो सकते?

CLI डेकोरेटर पढ़कर AppRouter टाइप बनाता है, इसलिए टाइप का न होना या पुराना होना आम तौर पर इसका संकेत है कि CLI ने राउटर नहीं पकड़ा।

यह इनपुट के लिए कौन-सी वैलिडेशन लाइब्रेरी इस्तेमाल करती है?

यह इनपुट और आउटपुट स्कीमा के लिए Zod इस्तेमाल करती है।

क्या इंस्टॉल करना चाहिए?

nestjs-trpc पैकेज, tRPC v11 और Zod, साथ में NestJS में मॉड्यूल रजिस्ट्रेशन चाहिए।

जानकारी

लेखक का मूल विवरण

Build end-to-end type-safe tRPC APIs inside NestJS using the nestjs-trpc adapter — @Router/@Query/@Mutation/@Subscription decorators, TRPCModule.forRoot, injectable middlewares and context, Zod input/output schemas, and the Rust CLI that generates the AppRouter type for clients. Use this skill whenever the user mentions nestjs-trpc, tRPC in a NestJS app, @Router or @Query decorators, TRPCModule, AppRouterHost, "typed API between my Nest backend and frontend", generating AppRouter types, or is migrating a NestJS GraphQL/REST API to tRPC — even if they don't name the library explicitly.

repo: trycompai/crm

लोकप्रियता

GitHub स्टार
12k
रैंकिंग में स्थान
#11521
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

ai-elements

12k

यह आपके एजेंट को बातचीत, संदेश, टूल डिस्प्ले और प्रॉम्प्ट इनपुट के लिए तैयार कॉम्पोनेंट से AI चैट इंटरफ़ेस बनाने में मदद करती है।

कोडिंगवेबसाइट और UI (frontend)

ai-sdk

12k

यह आपके एजेंट को Vercel AI SDK से AI फ़ीचर बनाने में मदद करती है, जिसमें टेक्स्ट जनरेशन, स्ट्रीमिंग, टूल कॉलिंग और एजेंट शामिल हैं।

AI और एजेंटएजेंट

better-accessibility

12k

यह आपके एजेंट को इंटरफ़ेस को कीबोर्ड और स्क्रीन रीडर के लिए उपयोगी बनाने में मदद करती है, जिसमें फ़ोकस, लेबल, ARIA और फ़ॉर्म शामिल हैं।

डिज़ाइनइंटरफ़ेस (UI/UX)

better-auth-best-practices

12k

यह आपके एजेंट को TypeScript ऐप में लॉगिन, सेशन, OAuth और प्लगइन के लिए Better Auth सेट करने में मदद करती है, उसके दस्तावेज़ी चरणों के अनुसार।

कोडिंगसिक्योरिटी

मिलती-जुलती skills