Skip to main content

Build

Trpc Conventions

tRPCOfficial

tRPC's test setup and TypeScript conventions, which win where the generic pstack tdd, typescript-best-practices and principle-type-system-discipline skills disagree. Use when fixing a bug, writing or changing tests, or writing or reviewing TypeScript in packages/.

  • New
  • v1.0.1
  • No reviews yet

Getting started

Full instructions

Install the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.

Instructions: SKILL.mdv1.0.1

tRPC conventions

Tests

  • Every bug fix gets a regression test that fails without the fix, even when the test path is an integration test. Put it in packages/tests/server/regression/issue-<number>-<slug>.test.ts, or beside the code's existing tests (the legacy React package has packages/react-query/test/regression/).

  • Test through a real client and server. testServerAndClientResource is in @trpc/client/__tests__/testClientResource; the React packages have their own helpers, so copy the setup from the nearest test.

    ts
    await using ctx = testServerAndClientResource(router);
    
  • Watch it fail, then pass: pnpm vitest run <file> from the repo root.

  • The PR's Regression check: line names the test and what it catches without the fix.

  • In new tests, wait on a condition with vi.waitFor rather than a fixed sleep.

  • No beforeEach, beforeAll, afterEach or afterAll (vitest/no-hooks). Each test sets up what it needs with using/await using: a helper returns a disposable that undoes its setup, such as using _timers = fakeTimersResource(). Share expensive read-only setup with a memoised getter instead of beforeAll.

  • Add tests; don't rewrite or weaken existing ones unless the expected behaviour changed and the PR says why.

TypeScript

  • Internal (non-exported) parameters, properties and options are required. Pass absence explicitly as null, undefined, a literal or a symbol, whichever fits: x: T | undefined that every caller passes is fine, but not x?: T or an optional or defaulted parameter. Optionals are only conveniences on public APIs; normalise a public options object once at the boundary into a fully required internal shape.

    ts
    function connect(url: string, retry?: RetryOptions); // before
    function connect(url: string, retry: RetryOptions | null); // after
    
  • Take one options object, opts, and read its members. Destructure only keys read three or more times.

  • Clean up with await using and makeResource() or makeAsyncResource(), not try/finally.

  • Brands use __brand, as in stream/tracked.ts. any is fine in generic constraints such as AnyRouter. Declare return types only on public APIs.

  • Lint (.oxlintrc.json, tooling/oxlint-plugin/) already enforces type imports, at most three parameters, type-parameter names, no non-null assertions and exhaustive switches.

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from tRPC

View source →
non-json-content-typesHandle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from…2 installsvalidatorsConfigure input and output validation with .input() and .output() using Zod, Yup, Superstruct, ArkType, Valibot, Effect, or custom validator functions. Chain multiple .input() calls to merge object schemas. Standard Schema protocol…1 installsprinciple-encode-lessons-in-structureApply when you catch yourself writing the same instruction a second time, or notice a recurring correction. Encode the rule as a lint, metadata flag, runtime check, or script instead of more text.0 installsmiddlewaresCreate and compose tRPC middleware with t.procedure.use(), extend context via opts.next({ ctx }), build reusable middleware with .concat() and .unstable_pipe(), define base procedures like publicProcedure and authedProcedure. Access raw…0 installsnextjs-app-routerFull end-to-end tRPC setup for Next.js App Router. Covers route handler with fetchRequestHandler (GET + POST exports), TRPCProvider with QueryClientProvider, createTRPCOptionsProxy for RSC prefetching, HydrateClient/HydrationBoundary for…0 installserror-handlingThrow typed errors with TRPCError and error codes (NOT_FOUND, UNAUTHORIZED, BAD_REQUEST, INTERNAL_SERVER_ERROR), configure errorFormatter for client-side Zod error display, handle errors globally with onError callback, map tRPC errors to…0 installs

Frequently asked questions about trpc-conventions

What does the trpc-conventions skill do?

tRPC's test setup and TypeScript conventions, which win where the generic pstack tdd, typescript-best-practices and principle-type-system-discipline skills disagree. Use when fixing a bug, writing or changing tests, or writing or reviewing TypeScript in packages/. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the trpc-conventions skill?

Run `npx @skills-hub-ai/cli install trpc-conventions` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/trpc-conventions/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does trpc-conventions work with?

trpc-conventions runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the trpc-conventions skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use trpc-conventions after installing it?

In Claude Code, type `/trpc-conventions` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the trpc-conventions skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/trpc-conventions)](https://skills-hub.ai/skills/trpc-conventions)
HTML
<a href="https://skills-hub.ai/skills/trpc-conventions"><img src="https://skills-hub.ai/api/badges/skill/trpc-conventions" alt="Install on Skills Hub"></a>

More options in the badge docs.