Search code examples
javascriptfirebasegoogle-cloud-functionstslint

firebase error TS7006: Parameter 'snapshot' implicitly has an 'any' type


I am getting following lint error:

error TS7006: Parameter 'snapshot' implicitly has an 'any' type.

on following firebase cloud function:

exports.createTeamMember = functions.firestore
  .document(`teamProfile/{teamId}/teamMemberList/{newUserId}`)
  .onCreate(async (snapshot, context) => {
    const id: string = snapshot.data().id;
    const email: string = snapshot.data().email;
    const teamId: string = snapshot.data().teamId;
  });

Solution

  • Since you are using TSLint, must provide type for the arguments snapshot and context as follows:

    import * as admin from 'firebase-admin';
    import { EventContext } from 'firebase-functions';
    
    exports.createTeamMember = functions.firestore
      .document(`teamProfile/{teamId}/teamMemberList/{newUserId}`)
      .onCreate(async (snapshot: admin.firestore.DocumentSnapshot, context: EventContext) => {
        const id: string = snapshot.data().id;
        const email: string = snapshot.data().email;
        const teamId: string = snapshot.data().teamId;
      });