Closed JamieCurnow closed 2 years ago
This would require typescript
to be updated from 3.8.3
to at least 4.1.0
which will probably be a block.
Thanks for suggesting this. We are considering this for our next breaking change release (based on a similar suggestion here: https://github.com/firebase/firebase-js-sdk/issues/4277)
I think maybe this is causing a problem conflict between firebase-admin@10.0.1 and @google-cloud/firestore@5.0.1.
node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, BulkWriter, BulkWriterError, WriteBatch, SetOptions, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, CollectionGroup, QueryPartition, FieldValue, FieldPath, Timestamp, BundleBuilder, v1beta1, v1, OK, CANCELLED, UNKNOWN, INVALID_ARGUMENT, DEADLINE_EXCEEDED, NOT_FOUND, ALREADY_EXISTS, PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, ABORTED, OUT_OF_RANGE, UNIMPLEMENTED, INTERNAL, UNAVAILABLE, DATA_LOSS, UNAUTHENTICATED, FirebaseFirestore
23 declare namespace FirebaseFirestore {
~~~~~~~
node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
23 declare namespace FirebaseFirestore {
~~~~~~~
Conflicts are in this file.
node_modules/@google-cloud/firestore/types/firestore.d.ts:71:25 - error TS2315: Type 'UpdateData' is not generic.
71 ? {[K in keyof T]?: UpdateData<T[K]> | FieldValue} & NestedUpdateFields<T>
~~~~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:104:28 - error TS2315: Type 'UpdateData' is not generic.
104 AddPrefixToKeys<K, UpdateData<V>>
~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:282:5 - error TS2374: Duplicate index signature for type 'string'.
282 [key: string]: any; // Accept other properties, such as GRPC settings.
~~~~~~~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:644:13 - error TS2315: Type 'UpdateData' is not generic.
644 data: UpdateData<T>,
~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:789:13 - error TS2315: Type 'UpdateData' is not generic.
789 data: UpdateData<T>,
~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:999:13 - error TS2315: Type 'UpdateData' is not generic.
999 data: UpdateData<T>,
~~~~~~~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:1209:13 - error TS2315: Type 'UpdateData' is not generic.
1209 data: UpdateData<T>,
~~~~~~~~~~~~~
node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, BulkWriter, BulkWriterError, WriteBatch, SetOptions, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, CollectionGroup, QueryPartition, FieldValue, FieldPath, Timestamp, BundleBuilder, v1beta1, v1, OK, CANCELLED, UNKNOWN, INVALID_ARGUMENT, DEADLINE_EXCEEDED, NOT_FOUND, ALREADY_EXISTS, PERMISSION_DENIED, RESOURCE_EXHAUSTED, FAILED_PRECONDITION, ABORTED, OUT_OF_RANGE, UNIMPLEMENTED, INTERNAL, UNAVAILABLE, DATA_LOSS, UNAUTHENTICATED, FirebaseFirestore
23 declare namespace FirebaseFirestore {
~~~~~~~
node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
23 declare namespace FirebaseFirestore {
~~~~~~~
Conflicts are in this file.
node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:174:5 - error TS2374: Duplicate index signature for type 'string'.
174 [key: string]: any; // Accept other properties, such as GRPC settings.
~~~~~~~~~~~~~~~~~~~
Found 10 errors.
Seems like the TypeScript version for this package is already updated to support this.
It always surprises me that all the different node Firebase packages have different implementations of the types for Firebase...
@rgant Your error suggests that you are using two different versions of Firestore. Can you confirm whether your build is using more than one version?
Unrelated to this, since we published 5.x, this issue can now be closed. We have updated our converter code to enforce type safety for update()
calls.
I believe these are the latest versions of both tools:
firebase-admin@10.0.1 - For Firebase Functions to access Firestore. (https://firebase.google.com/docs/functions/get-started)
@google-cloud/firestore@5.0.1 - To setup a scheduled backup of Firestore. (https://firebase.google.com/docs/firestore/solutions/schedule-export)
Both as per the documentation best I can tell. Seems odd these two tools aren't in sync with the types.
Any advice where I should post this issue? To my eye, @google-cloud/firestore@5 types are less useful compared to firebase-admin@10.
Can you post the output of "npm list"?
Click to expand:
You have both "@google-cloud/firestore@4.15.1" and "@google-cloud/firestore@5.0.1". Until firebase-admin pulls in 5.x, you should depend on "@google-cloud/firestore@4.15.1".
That is listed as an optional dependency in firebase-admin's package.json. I wouldn't have expected that to cause issues. Seems like something in npm should warn me about these conflicts.
Thanks!
@schmidt-sebastian is there any code from here that's still relelvant: https://gist.github.com/JamieCurnow/650ea759c277757ae5665ea52400713b also https://javascript.plainenglish.io/using-firestore-with-more-typescript-8058b6a88674
Sorry for spamming, jamie has a v9 article here: https://plainenglish.io/blog/using-firestore-with-typescript-in-the-v9-sdk-cf36851bb099
I wanted to know why is this closed, I am using "firebase-admin": "^11.11.0"
And i still find this issue when using dot notation with withconverter
@ljrodriguez1 I think it's because UpdateData is now included / exported from firebase-admin since it upgraded its @google-cloud/firestore
dependency.
import type { UpdateData } from "firebase-admin/firestore";
So you can use that to type your data as described in this article by @JamieCurnow
PS: Tantiantially related, does anyone here know if/when the firestore API from firebase-admin / @google-cloud/firestore will transition to the same "modular" API as the web SDK >=v9?
@0x80 But that UpdateData does not support dot notation, and differs from the UpdateData implementation from the article.
because of that when doing db.collection("example").doc("exampleId").update(updates)
it throws a typescript error if i use the UpdateData from the article that supports dot notation
@ljrodriguez1 Ah ok that's good to know! I didn't fully understand your problem then.
Maybe @schmidt-sebastian or @thebrianchen can chime in...?
Is your feature request related to a problem? Please describe. This package works great with Typescript when using the
.withConverter
method and enforces correct types when performing aget()
orset()
oronSnapshot()
, but fails to enforce types on theupdate()
method.With TS v4.1 we can now safely enforce that dot-notation strings as object keys are correct, so we can do better than:
Check it out...
Describe the solution you'd like I propose that the helper types for creating a type that is able to handle object paths should be added to
FirebaseFirestore.UpdateData
. I think that a solution could look like this:Which would allow type safety like this:
Additional context Proposed solution in action: