googleapis / nodejs-firestore

Node.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
https://cloud.google.com/firestore/
Apache License 2.0
642 stars 149 forks source link

Unable to build with 5.0.2 (TypeScript errors) #1659

Open vthommeret opened 2 years ago

vthommeret commented 2 years ago

Environment details

Steps to reproduce

  1. Call npm run build within Firebase Functions folder

Output

[main] ./firebase/functions $ npm run build

> build
> tsc

node_modules/@google-cloud/firestore/types/firestore.d.ts:117:29 - error TS1005: ']' expected.

117     {[K in keyof T & string as `${Prefix}.${K}`]+?: T[K]};
                                ~~

node_modules/@google-cloud/firestore/types/firestore.d.ts:117:48 - error TS1005: ';' expected.

117     {[K in keyof T & string as `${Prefix}.${K}`]+?: T[K]};
                                                   ~

node_modules/@google-cloud/firestore/types/firestore.d.ts:117:50 - error TS1109: Expression expected.

117     {[K in keyof T & string as `${Prefix}.${K}`]+?: T[K]};
                                                     ~

node_modules/@google-cloud/firestore/types/firestore.d.ts:117:51 - error TS1109: Expression expected.

117     {[K in keyof T & string as `${Prefix}.${K}`]+?: T[K]};
                                                      ~

node_modules/@google-cloud/firestore/types/firestore.d.ts:2278:1 - error TS1128: Declaration or statement expected.

2278 }
     ~

Found 5 errors.

I see this on 5.0.0, 5.0.1, and 5.0.2. Running on 4.15.1 I see no errors.

schmidt-sebastian commented 2 years ago

@vthommeret Thanks for reporting this. We are building with 4.x ourselves. I will see if we can support both versions, but it will take a couple of days.

schmidt-sebastian commented 2 years ago

What version of TypeScript are you using?

vthommeret commented 2 years ago

4.5.4

schmidt-sebastian commented 2 years ago

I am not able to reproduce this error using a new project. Are you able to share a test projects? I tested both using a blank project and using the firebase-functions project as created by the Firebase CLI.

vthommeret commented 2 years ago

OK I figured out the issue as I was running into other dependencies that wouldn't pass type checking. While my global TypeScript was 4.5.4, it looks like the default TypeScript installed when you do firebase init and choose "functions" is 3.8.0:

https://github.com/firebase/firebase-tools/blob/master/templates/init/functions/typescript/package.lint.json#L27 https://github.com/firebase/firebase-tools/blob/master/templates/init/functions/typescript/package.nolint.json#L20 https://github.com/firebase/firebase-tools/blob/master/templates/extensions/typescript/package.lint.json#L15 https://github.com/firebase/firebase-tools/blob/master/templates/extensions/typescript/package.nolint.json#L12

When I manually upgraded the local TypeScript to 4.5.5, I was able to build 5.0.2. Is this an issue that should be filed in the firebase-tools project?

The version of Firebase Tools I'm running is 10.1.0 / it's strange that it compiles for you when created via the Firebase CLI since it seems like 3.8.0 is part of the base template.

schmidt-sebastian commented 2 years ago

We have not yet updated the @google-cloud/firestore dependency of firebase-admin yet. This is a prerequisite which should allow us to update firebase-functions and the CLI. I will follow up internally.

jasperverbeet commented 2 years ago

To confirm, I'm having the same issue. However, I was able to build with TS ^3.8.0 & Firestore ^4.15.1

`TS 4.5.1` & `Firestore 5.0.2`, doesn't seem to build as suggested above. Exits with the following errors. (click to expand) ```ts > tsc 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 | FieldValue} & NestedUpdateFields ~~~~~~~~~~~~~~~~ node_modules/@google-cloud/firestore/types/firestore.d.ts:104:28 - error TS2315: Type 'UpdateData' is not generic. 104 AddPrefixToKeys> ~~~~~~~~~~~~~ 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:655:13 - error TS2315: Type 'UpdateData' is not generic. 655 data: UpdateData, ~~~~~~~~~~~~~ node_modules/@google-cloud/firestore/types/firestore.d.ts:806:13 - error TS2315: Type 'UpdateData' is not generic. 806 data: UpdateData, ~~~~~~~~~~~~~ node_modules/@google-cloud/firestore/types/firestore.d.ts:1029:13 - error TS2315: Type 'UpdateData' is not generic. 1029 data: UpdateData, ~~~~~~~~~~~~~ node_modules/@google-cloud/firestore/types/firestore.d.ts:1254:13 - error TS2315: Type 'UpdateData' is not generic. 1254 data: UpdateData, ~~~~~~~~~~~~~ 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. ```
gmcdowell commented 2 years ago

I too have run into the same issue.

The clash appears to be related to a namespace declaration with 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/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

package.json snippet

"dependencies": {
    "@algolia/client-search": "^4.13.0",
    "@google-cloud/firestore": "^5.0.2",
    "@google-cloud/pubsub": "^2.19.0",
    "@google-cloud/storage": "^5.19.0",
    "@google-cloud/vision": "^2.4.2",
    "@googlicius/build-url": "^1.0.11",
    "@types/node": "^17.0.23",
    "@types/node-fetch": "^2.6.1",
    "algoliasearch": "^4.13.0",
    "csv-parse": "^5.0.4",
    "firebase-admin": "^10.0.2",
    "firebase-dynamic-links": "^1.1.0",
    "firebase-functions": "^3.20.0",
    "handlebars": "^4.7.7",
    "jimp": "^0.16.1",
    "line-segmentation-algorithm-to-gcp-vision": "^1.0.2",
    "node-fetch": "2.6.7",
    "yup": "^0.32.11"
  },
"devDependencies": {
    "@firebase/rules-unit-testing": "^2.0.2",
    "@types/faker": "5.5.9",
    "@types/jest": "^27.4.1",
    "@typescript-eslint/eslint-plugin": "^5.18.0",
    "@typescript-eslint/parser": "^5.18.0",
    "eslint": "^8.12.0",
    "eslint-plugin-import": "^2.26.0",
    "faker": "5.5.3",
    "firebase-functions-test": "^0.3.3",
    "jest": "^27.5.1",
    "jest-fetch-mock": "^3.0.3",
    "ts-jest": "^27.1.4",
    "ts-mockito": "^2.6.1",
    "ts-node": "^10.7.0",
    "typescript": "^4.6.3",
    "yargs": "^17.4.0"
  },
gugahoi commented 2 years ago

I am experiencing the same as above after trying to update @google-cloud/firestore and firebase-admin to latest versions. Given this problem was acknowledged almost 4 months ago, is there an ETA for a fix or an update?

dconeybe commented 2 years ago

Hello All. I'm taking over this issue from @schmidt-sebastian but, unfortunately, I don't have the breadth of knowledge that he had. Could someone provide a GitHub repo that I could clone to reproduce this problem?

trex-quo commented 2 years ago

I can provide a code snippet that is giving me a typescript error if that is helpful.

Code:

  return admin()
    .firestore()
    .runTransaction(async (t) => {
      const doc: any = await t.get(goalSnap.ref);
      const updatedRun = {
        status: "running",
        startTime: moment().valueOf(),
      };
      t.update(doc.ref, {
        [databaseConstants.users.goals.analysisEngineRuns]: updatedRun,
      });
      return false;
    });

TS error:

Argument of type '{ [x: string]: { status: string; startTime: number; }; }' is not assignable to parameter of type '{ [x: string]: FieldValue | { status?: string | FieldValue | undefined; startTime?: number | FieldValue | undefined; } | undefined; } & AddPrefixToKeys<string, { ...; }>'.
  Type '{ [x: string]: { status: string; startTime: number; }; }' is not assignable to type 'AddPrefixToKeys<string, { status?: string | FieldValue | undefined; startTime?: number | FieldValue | undefined; }>'.
    'string' and '`${string}.status`' index signatures are incompatible.
      Type '{ status: string; startTime: number; }' is not assignable to type 'string | FieldValue | undefined'.ts(2345)

This error is specifically referring to the second argument of the t.update function

This is with "@google-cloud/firestore": "^5.0.2" and "firebase-admin": "^11.0.0"

gdieguez commented 2 years ago

Hey @dconeybe, any updates on this?

dconeybe commented 2 years ago

No updates. I would love to dive into this more, but my time is limited. If someone could provide a git repo that I could clone and reproduce that would make it much quicker for me to investigate :wink: :wink: