Node.js 将Typescript转换为firebase函数的javascript
我已经开始钻研firebase的云功能,但作为一名Android开发人员,在这么长时间后重新使用javascript是很困难的 我已使用firebase命令行工具(即firebase登录/init/deploy)配置了一个新项目。还有npm和所有需要的依赖项 我正在使用Webstorm进行开发,并决定根据youtube上的视频尝试使用Typescript [ 我已经设法编译了我的Typescript,但是当转换到javascript时,它无法正确编译 有人能帮我解决这个问题吗 TS脚本如下Node.js 将Typescript转换为firebase函数的javascript,node.js,typescript,firebase-realtime-database,firebase-cloud-messaging,google-cloud-functions,Node.js,Typescript,Firebase Realtime Database,Firebase Cloud Messaging,Google Cloud Functions,我已经开始钻研firebase的云功能,但作为一名Android开发人员,在这么长时间后重新使用javascript是很困难的 我已使用firebase命令行工具(即firebase登录/init/deploy)配置了一个新项目。还有npm和所有需要的依赖项 我正在使用Webstorm进行开发,并决定根据youtube上的视频尝试使用Typescript [ 我已经设法编译了我的Typescript,但是当转换到javascript时,它无法正确编译 有人能帮我解决这个问题吗 TS脚本如下 im
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"
]
}
如果有人对此有任何想法,我将非常感谢任何帮助。我发现了我的问题,我在Webstorm 5.1中设置了一个旧版本的javascript进行编译。升级到6解决了问题
编译的代码是有效且正确的ES6代码。请尝试在
tsconfig.json
中指定“target”:“es5”
。顺便问一下,什么软件告诉您=>
是语法错误?