我有以下功能
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 的接口?
这行不通?
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;
}>;
}