简体   繁体   中英

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. I now have a Firestore trigger written in external JavaScript file( notifyNewMessage.js ), which I would like to somehow declare in the Typescript file.

Both files are in the same directory:

在此处输入图片说明


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
}

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 :)

Thanks in advance!

Assuming you are trying to import an exported function from the js file. Wouldn't it be something simple as one of the following:

import notifyNewMessage from "./notifyNewMessage";

OR

import { notifyNewMessage } from "./notifyNewMessage";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM