【问题标题】:Error: Property 'onChange' does not exist on type 'ObjectBuilder'错误:“ObjectBuilder”类型上不存在属性“onChange”
【发布时间】:2019-01-12 10:48:24
【问题描述】:

我的 Ionic 打字稿代码需要帮助。

这使用 Google Cloud Vision API 来标记您上传到 Firebase 存储的照片。

我的问题:(返回以下错误)

错误 TS2339:“ObjectBuilder”类型上不存在属性“onChange”。 npm 错误!代码生命周期 npm 错误!函数@构建:'tsc'

我的 ts 文件:

import * as functions from 'firebase-functions';

import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);

import * as vision from '@google-cloud/vision';
const visionClient = new vision.ImageAnnotatorClient();

//may need to delete, use default
const bucketName = 'outsidehax.appspot.com';

export const imageTagger = functions.storage
.bucket(bucketName)
.object()
.onChange( async event => {
    const object = event.data;
    const filePath = object.name;

    const imageUri = 'gs://'+bucketName+'/'+filePath;

    const docId = filePath.split('.jpg')[0];

    const docRef = admin.firestore().collection('photos').doc(docId);

    const results = await visionClient.labelDetection(imageUri);

    const labels = results[0].labelAnnotations.map(obj => obj.description);
    const sad = labels.includes('sad');

    return docRef.set({ sad, labels })

});

这个 index.ts 文件位于 AppName/functions/src/index.ts。

【问题讨论】:

    标签: typescript firebase google-cloud-firestore


    【解决方案1】:

    您使用的是在 firebase-functions SDK 达到 1.0 时更改的旧 API。 Please read about the changes here。不再有 onChange 事件。您应该改用其他事件之一,并确保了解它如何接收事件。

    您应该注意其他一些变化,例如不带参数初始化管理 SDK:

    admin.initializeApp()
    

    【讨论】:

      猜你喜欢
      • 2018-01-29
      • 2022-09-23
      • 2019-07-20
      • 2019-02-18
      • 2019-01-21
      • 2017-03-01
      • 2016-08-13
      • 2021-05-17
      • 1970-01-01
      相关资源
      最近更新 更多