Reputation: 15
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!
Upvotes: 0
Views: 385
Reputation: 11
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";
Upvotes: 1