Type-Safe Firestore Paths in a Shared Package: Let the App Register Its Own Types
On the OTP project we are moving to a monorepo with several microfrontends. At least three apps talk to Firestore, and all of them had their own copies of the same hooks: subscribe to a document, subscribe to a query, wait for the current user. The obvious move is to pull those hooks into a shared @repo/react-firestore package.
The catch is typing. Each app owns its own Firestore schema: workspaces/{id}/projects, users/{id}/chats, and so on. The shared package must not know those paths. But if the hook just takes path: string, we lose the typo protection we had when each app typed its own hooks.
This post shows the pattern we used: the package declares an empty registry, each app fills it in through declaration merging, and the package's hooks derive their parameter types from whatever the app registered.
