Util functions for Typescript Utility types #113
-
It might be nice to have a set of utility functions in ts_serialize that help handle the deserialization of some common Typescript Utility types. Typescript Records are one example. Instead of having some flavour of // response is of type Record<ClassA, ClassB>
const data: Record<ClassA, ClassB> = {};
Object.keys(response).forEach(key => (data[key] = new ClassB().fromJSON(response[key])));
return data; in multiple places, a set of utility functions that accept a I also understand if this goes beyond the scope of the ts_serialize library! It does seem adjacent to core functionality and is easily added to a project's utilities. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey, @rdraward-mindbridge 👋 Thanks for starting this discussion. Would you be able to provide a gist? I might be misunderstanding the request. We can add more strategies (I've been cautious in the past about adding strategies but have slowly changed my mind depending on the strategy), if you have an example of what you are thinking (or even want to make a PR) please send it our way! Please also consider both directions for this, fromJSON -> Serializable, Serializable -> toJSON. Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hey, @rdraward-mindbridge just following up on the request. If you provide us with some more information we can most likely help out in any way needed. Cheers, |
Beta Was this translation helpful? Give feedback.
-
I wanted to follow up again to see if you had any further thoughts on adding custom strategies. In the example you provided - it seems that we have already added one for that use case |
Beta Was this translation helpful? Give feedback.
@rdraward-mindbridge 👋
I wanted to follow up again to see if you had any further thoughts on adding custom strategies.
In the example you provided - it seems that we have already added one for that use case
toObjectContaining
andfromObjectContaining