FirebaseExtended / FirebaseExtended/rxfire

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

Open
#93 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
149
Forks
50
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/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
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](https://github.com/ds300/patch-package/issues/296).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.