We’ve use an API style similar to tRPC at Notion, although our API predated tRPC by 4 years or so. You can build this kind of thing yourself easily using Typescript’s mapped types, by building an object type where the keys are your API names, and the values are { request, response } types. Structure your “server” bits to define each API handler as a function taking APIs[“addUser”][“request”] and returning Promise . T…
I also wrote a 10-line mock API wrapper that you can call as mockApi((request) => response), and it will type-check that your mock function implements the API correctly and return a function that looks exactly like the real API function.
[0]: https://github.com/ferdikoomen/openapi-typescript-codegen