[英]How to call External Javascript Firestore function in a Typescript file?
I am using Node.js to upload a Typescript file( index.ts ) with Cloud functions.我正在使用 Node.js 上传带有云函数的 Typescript 文件( index.ts )。 I now have a Firestore trigger written in external JavaScript file( notifyNewMessage.js ), which I would like to somehow declare in the Typescript file.
我现在有一个用外部 JavaScript 文件( notifyNewMessage.js )编写的 Firestore 触发器,我想以某种方式在 Typescript 文件中声明。
Both files are in the same directory:两个文件都在同一个目录下:
index.ts:索引.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通知新消息.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
}
It would be great if anyone can provide a way for me to do this, or point me in a direction where I can learn how, as Typescript and JavaScript are not my strong points :)如果有人能为我提供一种方法来做到这一点,或者指出我可以学习的方向,那就太好了,因为 Typescript 和 JavaScript 不是我的强项:)
Thanks in advance!提前致谢!
Assuming you are trying to import an exported function from the js file.假设您正在尝试从 js 文件导入导出的函数。 Wouldn't it be something simple as one of the following:
难道不是以下简单的事情之一:
import notifyNewMessage from "./notifyNewMessage";
OR或者
import { notifyNewMessage } from "./notifyNewMessage";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.