Remix.run Logo
ngrilly 4 days ago

I'm familiar with zod.infer but I'm not sure how to use it to produce an interface that would be compatible with RpcStub and RpcTarget, like MyApi in the example in your post:

  // Shared interface declaration:
  interface MyApi {
    hello(name: string): Promise<string>;
  }

  // On the client:
  let api: RpcStub<MyApi> = newWebSocketRpcSession("wss://example.com/api");

  // On the server:
  class MyApiServer extends RpcTarget implements MyApi {
    hello(name) {
      return `Hello, ${name}!`
    }
  }
kentonv 4 days ago | parent [-]

I'll be honest and say I haven't tried it myself.

But my expectation is you'd use Zod to define all your parameter types. Then you'd define your RpcTarget in plain TypeScript, but for the parameters on each method, reference the Zod-derived types.