david
How to treat mongoose/mongodb ObjectIDs as their serialized string values on the frontend?
Node Environment Version: v20.10.0
Package Manager: PNPM Workspaces
Repo Setup: Monorepo/Turborepo
Environment: WSL with VSCode
TRPC Versions:
If I have a query procedure as follows:
and a simple frontend render on react as follows:
The frontend gives an error like:
However. The actual serialized value is of course a
string
for each _id
. What is the current expectation to handle these values? Of course, you can manually say String(user._id)
but is there a more appropriate method to handle this? Like a way to inform TS that these are strings and not ObjectId's on the frontend? I've tried my best to look at some other threads mentioning it, they however seem to mention declaring additional zod output schemas which feels quite cumbersome if you're intending on having varying different data returned.
The goal is to have the values treated as strings i feel.
Thanks for any help guys :)3 replies
All backend imports becoming accessible on frontend?
Node Environment Version: v20.10.0
Package Manager: PNPM Workspaces
Repo Setup: Monorepo/Turborepo
Environment: WSL with VSCode
TRPC Versions:
Hello! First time user of TRPC.
I've setup my project, and now have it so that it exports appRouter on the backend
Backend
Then on the frontend like the tutorial I have a hooks file for trpc that imports the backend
Frontend
The structure is setup as follows
However in VSCode all other backend imports are displayed during autoimport now in the frontend project? For example I can now do something like
When the line to import AppRouter is removed, none of the backend autocomplete imports appear.
I realistically would only like to expose that type and nothing else, I don't think imports actually work, as in Vite/React will throw errors when you try to use that backend import them during runtime. But is there a way to prevent the other imports from appearing? Is this behaviour expected?
I also tried to use pnpm link and export only a file containing the AppRouter but this didn't seem to prevent it either
Backend package.json
Backend trpc.types.ts
Frontend
10 replies