Replies: 5 comments
-
@Ehesp Thanks for this well thought out request! This is definitely something we can add as it is a non-breaking change. We're currently working on getting other QoL improvements shipped, but I'll revisit this in the future. |
Beta Was this translation helpful? Give feedback.
-
Having worked with converters on a few different projects now, I'm actually finding this to be a type limitation which is frequently popping up. Take the Firebase Toxicity Extension for example, it modifies documents with data based on what you enter (e.g. a Map called When adding a document in the current state, my code looks like so: type Review = {
attribute_scores: {
TOXICITY: number;
};
message: string;
}
.withConverter<Review>(...) The issue is, when calling say type Review = {
message: string;
}
type ReviewDocument = {
attribute_scores: {
TOXICITY: number;
};
} & Review;
.withConverter<Review, ReviewDocument>(...) |
Beta Was this translation helpful? Give feedback.
-
@Ehesp That's a good use case! We currently are prioritizing other features at the moment, but we'll definitely come back to this in the future. |
Beta Was this translation helpful? Give feedback.
-
Seems like this has been implemented in the modular js sdk, but not yet in the admin nodejs sdk. It's a shame there wasn't an easier way to keep the js and admin capabilities in sync :( |
Beta Was this translation helpful? Give feedback.
-
Hello,
The
withConverter
API currently accepts a single type, for example:Whilst using Firestore on a single platform (e.g. web) this is fine since I'm able to use the returned
User
instance in my code. This pattern however does not work when I need to deserialise the data. For example, an API endpoint needs to return a JSON serialisable response, and in this case the classUser
needs to be transformed, e.g:Although this is ok, it does lead to code duplication and potentially forgetting to call
toJson()
. Instead, would it be possible to provide a differentfromFirestore
data type in the withConverter API? Something like:Instead, I could declare the converter as so:
How the return type defaults to the original type (keeping backwards compatibility) but also allows to return a different type:
Beta Was this translation helpful? Give feedback.
All reactions