我已经开始深入研究firebase的云功能,但是在这么长时间之后成为一名Android开发者回到javascript中已经很难了。
我已使用firebase命令行工具配置了一个新项目,即firebase login / init / deploy。还有npm和所有需要的依赖项。
我正在使用Webstorm进行开发,并决定根据youtube上的视频尝试使用Typescript。
[https://www.youtube.com/watch?v=GNR9El3XWYo&t=1106s][1]
我设法得到了我的Typescript编译,但是当转换为javascript时它没有正确编译。
任何人都可以帮我解决这个问题吗?
下面的TS脚本
import * as functions from 'firebase-functions'
import * as request from 'request-promise'
export let addPlayerRequestNotification = functions.database
.ref('notifications/{id}/notification')
.onWrite(async event => {
let notificaion = event.data.val();
let oauthToken = await functions.config().firebase.credential.getAccessToken();
await request ({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type' :' application/json',
'Authorization': 'key='+oauthToken
},
body: {
"notification": {
"title": notificaion.title,
"text": notificaion.text,
},
to : '/topics/'+notificaion.topic
}
});
});
javascript编译的代码是
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const functions = require("firebase-functions");
const request = require("request-promise");
exports.addPlayerRequestNotification = functions.database
.ref('notifications/{id}/notification')
.onWrite((event) => __awaiter(this, void 0, void 0, function* () {
let notificaion = event.data.val();
let oauthToken = yield functions.config().firebase.credential.getAccessToken();
yield request({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type': ' application/json',
'Authorization': 'key=' + oauthToken
},
body: {
"notification": {
"title": notificaion.title,
"text": notificaion.text,
},
to: '/topics/' + notificaion.topic
}
});
}));
违规行就是这个
.onWrite((event) => __awaiter(this, void 0, void 0, function* () {
更具体地说,=>字符。我得到的错误是预期的表达。
这是我的tsconfig.json文件
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
},
"include": [
"functions/**/*.ts"
],
"exclude": [
"functions/node_modules"
]
}
如果有人对此有任何想法,我将非常感谢任何帮助。