Skip to content

Firestore Trigger V2 typing missing #1378

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

Closed
service-paradis opened this issue Apr 18, 2023 · 2 comments · Fixed by #1379
Closed

Firestore Trigger V2 typing missing #1378

service-paradis opened this issue Apr 18, 2023 · 2 comments · Fixed by #1379

Comments

@service-paradis
Copy link

Related issues

None

[REQUIRED] Version info

node: 18.13.0

firebase-functions: 4.3.0

firebase-tools: 11.27.0

firebase-admin: 11.6.0

[REQUIRED] Test case

Please follow the instructions provided in the official Firebase documentation at https://firebase.google.com/docs/functions/beta/firestore-events?hl=fr#trigger_a_function_for_all_changes_to_a_document.

[REQUIRED] Steps to reproduce

  1. Use TypeScript
  2. Add import { onDocumentWritten, Change, FirestoreEvent } from 'firebase-functions/v2/firestore'; to a file

[REQUIRED] Expected behavior

The function should work as described in the documentation.

[REQUIRED] Actual behavior

After building or serving the functions, I encountered an error message that says:

Module '"firebase-functions/v2/firestore"' declares 'Change' locally, but it is not exported.

node_modules/firebase-functions/lib/v2/providers/firestore.d.ts:3:10
3 import { Change, CloudEvent, CloudFunction } from "../core";
~~~~~~
'Change' is declared here.

To resolve this error, I removed Change from firebase-functions/v2/firestore and instead used import { Change } from 'firebase-functions'.

However, even after this modification, the function still did not work as stated in the documentation. I had to replace event.data.change.before and event.data.change.after with event.data.before and event.data.after, respectively, to get the desired results.

Were you able to successfully deploy your functions?

To compile the functions successfully, I had to make two changes:

  1. remove Change from firebase-functions/v2/firestore and import it using import { Change } from 'firebase-functions';
  2. use event.data.before and event.data.after instead of event.data.change.before or event.data.change.after

After these changes, Typescript stopped complaining. However, even after making these changes, the emulator did not recognize the function, and as a result, it did not work.

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@colerogers
Copy link
Contributor

@service-paradis Added export of the Change interface and we'll release a patch release soon! The docs should also get an update to remove change from the event path. Thanks!

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

Successfully merging a pull request may close this issue.

3 participants