#Why does Payload generated types have numbers as a possibility in so many relations?

1 messages · Page 1 of 1 (latest)

valid sail
#

A few examples from my generated types

image?: (number | null) | Image;

thumbnail?: (number | null) | Image;

youtube_channel: {
  link: string;
  name: string;
  image?: (number | null) | Image;
};

logo?: (number | null) | Image;```
This makes my typescript code worse, not a real problem but I was wondering if it's intentional
lean kiln
# valid sail A few examples from my generated types ```ts image?: (number | null) | Image; t...

100% intentional! That's because the data can be different depending on the depth.

If you query your document with depth=0, then image will be a number (the id of the image).

If you query it with depth=1, then image will be the populated image document (Image)

And if it doesn't exist it will be null or undefined (?)

So with ?: (number | null) | Image you actually have the perfect type which covers all possibilities!

valid sail