javascript - 如何在 Typescript 文件中调用外部 Javascript Firestore 函数?
问题描述
我正在使用 Node.js 上传带有云功能的 Typescript 文件( index.ts )。我现在有一个用外部 JavaScript 文件 ( notifyNewMessage.js ) 编写的 Firestore 触发器,我想以某种方式在 Typescript 文件中声明它。
这两个文件都在同一个目录中:
索引.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 不是我的强项:)
提前致谢!
解决方案
假设您正在尝试从 js 文件中导入导出的函数。这不是简单的事情之一吗:
import notifyNewMessage from "./notifyNewMessage";
或者
import { notifyNewMessage } from "./notifyNewMessage";
推荐阅读
- javascript - 更改数组的数据格式并删除键/值对
- java - 有效地将一行添加到现有 Excel 文件中
- jenkins - 如果其中一个存储库发生更改,则轮询多个存储库并触发构建
- jmeter - 如何生成一个日志文件,其中包含在 JMeter 脚本中执行的采样器的结果
- angular - 如何根据角度条件更改按钮颜色和状态?
- vb.net - VB NET 中的自动登录失败
- php - $wpdb>update 对数据库没有影响?
- json - 空手道:如果对象名称在数组中包含句点,如何设置 Json 值
- hive - 将逗号分隔的值拆分为行
- ios - 如何避免 iOS / Swift tableView 中的重复子视图