[英]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.