Hey, I'm using Payload in a project where our frontend fetches data via the REST API with a high enough depth to ensure all relations are fully populated.
We are importing the generated payload-types.ts file directly into our frontend repo to keep everything in sync. However, this is where the friction starts: the generated types (e.g., author: string | User) always include the ID string as a possibility.
Since we know for a fact that in our web app the object will always be there due to our fetch depth, we’re ending up with a ton of boilerplate:
- Constant
if (typeof author !== 'string')checks - Type guards or manual casting almost every component.
- Logic that feels "cluttered" because TypeScript isn't aware of our fetch depth.
So my question is, is there any config or a plugin for the type generator to emit only the interface/object type and exclude the string union for relations? Or is there any other cleaner way to handle these type checks?
Thanks in advance!