rxfire icon indicating copy to clipboard operation
rxfire copied to clipboard

Typing is lost when a converter is specified in versions > 6.0.3

Open anandsathe67 opened this issue 2 years ago • 2 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

In our project, we noticed we are losing typing information provided via a converter (#withConverter functions called on a collectionRef or docRef or a query) after upgrading to rxfire 6.0.5. The problem seems to be the use of the spread operator in

https://github.com/FirebaseExtended/rxfire/blob/6.0.5/firestore/document/index.ts#L57C7-L57C7

The spread operator will implicitly convert the data element to a JS object. Hence the calling code will lose the type information it expects.

Here is the diff that solved my problem:

diff --git a/node_modules/rxfire/firestore/index.cjs.js b/node_modules/rxfire/firestore/index.cjs.js
index ce4c892..d5cc630 100644
--- a/node_modules/rxfire/firestore/index.cjs.js
+++ b/node_modules/rxfire/firestore/index.cjs.js
@@ -114,7 +114,9 @@ function snapToData(snapshot, options) {
     if (!snapshot.exists() || typeof data !== 'object' || data === null || !options.idField) {
         return data;
     }
-    return __assign(__assign({}, data), (_a = {}, _a[options.idField] = snapshot.id, _a));
+    //return __assign(__assign({}, data), (_a = {}, _a[options.idField] = snapshot.id, _a));
+    data[options.idField] = snapshot.id;
+   return data;
 }
 
 /**
diff --git a/node_modules/rxfire/firestore/index.esm.js b/node_modules/rxfire/firestore/index.esm.js
index b942381..03497ec 100644
--- a/node_modules/rxfire/firestore/index.esm.js
+++ b/node_modules/rxfire/firestore/index.esm.js
@@ -110,7 +110,9 @@ function snapToData(snapshot, options) {
     if (!snapshot.exists() || typeof data !== 'object' || data === null || !options.idField) {
         return data;
     }
-    return __assign(__assign({}, data), (_a = {}, _a[options.idField] = snapshot.id, _a));
+    //return __assign(__assign({}, data), (_a = {}, _a[options.idField] = snapshot.id, _a));
+    data[options.idField] = snapshot.id;
+    return data;
 }
 
 /**

This issue body was partially generated by patch-package.

anandsathe67 avatar Nov 10 '23 05:11 anandsathe67

If you compare https://github.com/FirebaseExtended/rxfire/blob/6.0.5/firestore/document/index.ts#L57C7-L57C7 with https://github.com/FirebaseExtended/rxfire/blob/6.0.3/firestore/document/index.ts#L57C7-L57C7, you will notice the spread operator was not being used earlier

anandsathe67 avatar Nov 10 '23 05:11 anandsathe67

I have the same issue, with rxfire 6.0.5, by changing the lines that @anandsathe67 provided. Sloved the issue! Thanks @anandsathe67

hampusboas avatar Aug 21 '24 00:08 hampusboas