You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using ModelObject to create pojos version of my models so I can use them throughout my app. One thing I noticed is if a model has props that are also Models, the ModelObject type keeps them as Model types. instead of transforming them into ModelObjects too.
I created a DeepModelObject type that recursively checks for nested Models and transforms them into ModelObjects.
Nested models of models will be transformed also. I'm pretty new to TS so this took me a lot longer to figure out than I'd like to admit 😅, but thought I'd post here in case someone needs this.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using ModelObject to create pojos version of my models so I can use them throughout my app. One thing I noticed is if a model has props that are also Models, the ModelObject type keeps them as Model types. instead of transforming them into ModelObjects too.
I created a
DeepModelObject
type that recursively checks for nested Models and transforms them into ModelObjects.If I use
export type Product = DeepModelObject<DbProduct>
Nested models of models will be transformed also. I'm pretty new to TS so this took me a lot longer to figure out than I'd like to admit 😅, but thought I'd post here in case someone needs this.
Beta Was this translation helpful? Give feedback.
All reactions