如何向 Firebase Functions 处理程序 V2 添加类型?

问题描述 投票:0回答:1

我有以下功能

export async function onDeleteVideo(event: FirestoreEvent<QueryDocumentSnapshot, { uid: string }>): Promise<any> {
  if (!event) {
    return
  }

  const { disposables } = event.data.data()

  for (const disposable of disposables) {
    try {
      await storage.bucket(disposable.bucket).file(disposable.object).delete()
    } catch {}
  }
}

导出为

export const onDeleteVideo = onDocumentDeleted('videos/{uid}', triggers.onDeleteVideo)

但是,

event.data.data()
disposables
是任意的。如何添加我的类型,即名为 Video 的接口?

typescript firebase google-cloud-functions
1个回答
0
投票

这行不通?

export async function onDeleteVideo(event: FirestoreEvent<QueryDocumentSnapshot, Video>): Promise<any> {
  if (!event) {
    return
  }

  const { disposables } = event.data.data()

  for (const disposable of disposables) {
    try {
      await storage.bucket(disposable.bucket).file(disposable.object).delete()
    } catch {}
  }
}

Video
界面类似于:

interface Video {
  uid: string;
  disposables: Array<{
    bucket: string;
    object: string;
  }>;
}
© www.soinside.com 2019 - 2024. All rights reserved.