tRPC

tRPC

a toolkit for building end-to-end typesafe data layers

codecov GitHub License GitHub Stars

Server/client example
The client above is not importing any code from the server, only it's type declarations.
Import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there’s no remnant of it at runtime.

Introduction#

tRPC is a framework for building strongly typed RPC APIs with TypeScript. Alternatively, you can think of it as a way to avoid APIs altogether.

  • πŸ§™β€β™‚οΈΒ  Automatic type-safety & autocompletion inferred from your API-paths, their input data, outputs, & errors.
  • 🐎  Snappy DX. No code generation, run-time bloat, or build pipeline.
  • πŸƒΒ  Light. tRPC has zero deps and a tiny client-side footprint.
  • 🐻  Easy to add to your existing brownfield project.
  • πŸ”‹Β  Batteries included. React-library + Next.js/Express adapters. (But tRPC is not tied to React - reach out if you want to make a Svelte/Vue/... lib)
  • πŸ₯ƒΒ  Simple to use APIs for queries & mutations + experimental subscriptions support.
  • πŸ‘€Β  Quite a few examples in the ./examples-folder
  • βœ…Β  Well-tested & running in production.

Requirements#

  • tRPC requires TypeScript > 4.1 because of Template Literal Types, but you can get some benefits with autocompletion etc even if you use raw JS.