Add minDepth to relationship field to control generated type #3271
Replies: 2 comments 4 replies
-
Why is this annoying? And what does improve by doing this? Also, I think if the collection suddenly does not exist any more it returns the saved field in the db (a string) or you got the following case: Collection2 has a relationship field to Collection1 this returns the full object of Collection1 when retrieving Collection2. Now if we got a Collection3 that has an relationship to Collection2 and the depth is max 2 the relationship on Collection2 returns just the ID. |
Beta Was this translation helpful? Give feedback.
-
The discussion boils down to: How to solve the following type error the cleanest way possible: type Media = {
title: string
image: {
url: string
}
}
const post : Media | string = "Hello World!"
// gives error "Property 'image' does not exist on type 'string'.ts(2339)"
const imageUrl = post?.image?.url ?? "" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now, the generated type of a relationship is as follows
myrelationshipfield?: string[] | Collection[];
This is very annoying, because a string is string[] is never returned when using a depth for the API requests, right?
If so, I would like minDepth setting on the relationship field to turn the generated type into
myrelationshipfield?: Collection[];
Beta Was this translation helpful? Give feedback.
All reactions