Replies: 6 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. |
|
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>(...) |
|
@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. |
|
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 :( |
|
I've spent hours trying to make this work but it seems like a type limitation in the SDK itself. I can't find a way to fix this without patching the library myself. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
The
withConverterAPI 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
Userinstance 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 classUserneeds 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 differentfromFirestoredata 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:
All reactions