简体   繁体   English

将 Firebase Cloud Function TypeScript 语法转换为 JavaScript

[英]Convert Firebase Cloud Function TypeScript syntax to JavaScript

@DougStevenson published a nice cloud functions tutorial here , but his cloud function code snippet uses TypeScript rather than JavaScript. @DougStevenson 在这里发布了一个很好的云函数教程,但他的云函数代码片段使用的是 TypeScript 而不是 JavaScript。

How would one convert the following code to vanilla JavaScript?如何将以下代码转换为 vanilla JavaScript?

interface ClaimsDocumentData extends admin.firestore.DocumentData {
    _lastCommitted?: admin.firestore.Timestamp
}
export const mirrorCustomClaims =
functions.firestore.document('user-claims/{uid}')
.onWrite(async (change, context) => {
    const beforeData: ClaimsDocumentData =
        change.before.data() || {}
    const afterData: ClaimsDocumentData =
        change.after.data() || {}
})

Just strip the type data out of it.只需从中删除类型数据即可。

exports.mirrorCustomClaims =
functions.firestore.document('user-claims/{uid}')
.onWrite(async (change, context) => {
    const beforeData = change.before.data() || {}
    const afterData = change.after.data() || {}
})

You can also set up another project with TypeScript, add the code to it, compile it, and simply observe the transpiled JavaScript.您还可以使用 TypeScript 设置另一个项目,向其中添加代码,编译它,然后简单地观察转换后的 JavaScript。

The rest of that sample is likely to give you even more problems.该样本的其余部分可能会给您带来更多问题。 Strongly suggest adopting TypeScript, since all JavaScript is valid TypeScript, and you can adopt TypeScript features into your code at the rate you choose.强烈建议采用 TypeScript,因为所有 JavaScript 都是有效的 TypeScript,并且您可以按照您选择的速度在代码中采用 TypeScript 功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用云功能Firebase,JavaScript进行通知 - Notification with cloud function firebase, JavaScript Google Cloud Function:开玩笑的测试无法识别打字稿语法 - Google Cloud Function: jest test does not recognize typescript syntax 我可以在javaScript和typeScript中为firebase编写云函数吗? - Can I write cloud functions for firebase both in javaScript and typeScript? Firebase 云函数 – JavaScript/Typescript Promise reject() 问题 - Firebase Cloud Functions – JavaScript/Typescript Promise reject() issue How to parse json object in firebase cloud function typescript - How to parse json object in firebase cloud function typescript 创建对象/函数实例,将JavaScript转换为TypeScript - Create instance of object/function convert JavaScript to TypeScript 如何将 JavaScript 函数转换为在打字稿中工作 - How to convert JavaScript function to work in typescript 有没有办法将回调 function 转换为 TypeScript/JavaScript 中的生成器? - Is there a way to convert a callback function into a generator in TypeScript/JavaScript? Firebase 云 Function (Javascript) Firebase 部署时解析错误 - Firebase Cloud Function (Javascript) Parsing Error When Firebase Deploy Java中的Firebase Cloud Function。 Remove()函数不起作用 - Firebase Cloud Function in Javascript. Remove() function not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM