Vanilla client
The magic of tRPC is making strongly typed API calls without relying on code generation. With full-stack TypeScript projects, you can directly import types from the server into the client! This is a vital part of how tRPC works.
Import the AppRouter type into your client from the file your root tRPC router is defined. This single type represents the type signature of your entire API.
client.tsts
client.tsts
The import type keywords let you import from any TypeScript file on your filesystem. Plus import type can only import types, NOT code. So there's no danger of accidentally importing server-side code into your client. All calls to import type are always fully erased from your compiled JavaScript bundle (source).
Initialize a tRPC client
Create a typesafe client with the createTRPCClient method from @trpc/client:
client.tsts
client.tsts
As you can see, we passed AppRouter as a type argument of createTRPCClient. This returns a strongly typed client instance:
client.tsts
client.tsts