错误:类型“ ObjectBuilder”上不存在属性“ onChange”

时间:2018-08-05 04:09:28

标签: typescript firebase google-cloud-firestore

我需要有关离子打字稿代码的帮助。

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

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

  

错误TS2339:类型'ObjectBuilder'不存在属性'onChange'。   npm ERR!代码ELIFECYCLE   npm ERR! functions @ build:'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。

1 个答案:

答案 0 :(得分:1)

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

您还应该注意其他更改,例如不带参数初始化admin的SDK:

admin.initializeApp()