Skip to content

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

@anandsathe67

Description

@anandsathe67

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions