【问题标题】:How to call External Javascript Firestore function in a Typescript file?如何在 Typescript 文件中调用外部 Javascript Firestore 函数?
【发布时间】:2020-07-11 03:18:18
【问题描述】:

我正在使用 Node.js 上传带有云功能的 Typescript 文件(index.ts)。我现在有一个用外部 JavaScript 文件 (notifyNewMessage.js) 编写的 Firestore 触发器,我想以某种方式在 Typescript 文件中声明它。

两个文件都在同一个目录中:


index.ts:

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

//declare javascript file here???

export const cloudFunction= functions
  .firestore.document(`Users/{user_id}`).onWrite(async (change, _context) => {

   //Function code....

}


notifyNewMessage.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.notifyNewMessage = functions.firestore{
   //Cloud function I want to declare in index.ts
}

如果有人可以为我提供一种方法,或者指出我可以学习的方向,那就太好了,因为 Typescript 和 JavaScript 不是我的强项 :)

提前致谢!

【问题讨论】:

    标签: javascript typescript firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    假设您正在尝试从 js 文件中导入导出的函数。不是很简单,就像以下之一:

    import notifyNewMessage from "./notifyNewMessage";
    

    import { notifyNewMessage } from "./notifyNewMessage";
    

    【讨论】:

      猜你喜欢
      • 2017-02-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2011-02-25
      • 2021-05-07
      • 2013-09-15
      • 1970-01-01
      相关资源
      最近更新 更多