【问题标题】:firebase error TS7006: Parameter 'snapshot' implicitly has an 'any' typefirebase 错误 TS7006:参数“快照”隐式具有“任何”类型
【发布时间】:2020-01-06 09:02:23
【问题描述】:

我收到以下 lint 错误:

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

关于以下 Firebase 云功能:

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;
  });

【问题讨论】:

    标签: javascript firebase google-cloud-functions tslint


    【解决方案1】:

    由于您使用的是 TSLint,因此必须为参数 snapshotcontext 提供类型,如下所示:

    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;
      });
    

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多