0

I have a following code structure:

├── frontend/
│   ├── tsconfig.json
│   ├── src/**/*.ts[x]
├── shared/
│   ├── **/*.ts
├── server/
│   ├── tsconfig.json
│   ├── src/**/*.ts
├── project.json

There are already quite a few questions around the same topic like this, this and that. However, they all have different use cases. In these cases, they simply need to coexist inside a monorepo without needing to share the types between them except for the shared code in the shared/ folder which doesn't use any specific library like DOM, Node, etc. It is just bunch of utility modules.

My backend/server code is built using tRPC where I need to share the types with the frontend codebase that tRPC generates. The problem is I cannot just import server/src/trpc.ts file in a client code. When I try to import tRPC type for the client in frontend code, everything comes into the Typescript dependency graph due to transitive imports of the dependencies. The frontend code doesn't recognize the backend specific types like process, NodeJs, fs, etc.

So what's the best way to import the tRPC types from a server into a frontend codebase without making frontend Typescript configuration aware of all the Node types? As said, I just need types and not the actual code. (I prefer to avoid this as doing this means frontend code can have Node.js specific code which would compile but won't run in the browser)?

Harshal Patil
  • 17,838
  • 14
  • 60
  • 126

0 Answers0