Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anandsathe67 opened this issue Nov 10, 2023 · 2 comments
Open

Comments

@anandsathe67
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch rxfire@6.0.5 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
Copy link
Author

@hampusboas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants