错误:Firebase云功能中带阴影的名称:'request'

时间:2018-08-08 14:47:27

标签: typescript firebase google-cloud-functions

这是Firebase Cloud Function REST Api代码。

import { request } from "https";

const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const firestore = admin.firestore();

export const helloWorld = functions.https.onRequest((request, response) => {

   response.send("Hello from rocon!");
});

错误是:

ERROR: /Users/hello/Computer/Development/server/ts_test/functions/src/index.ts[13, 54]: Shadowed name: 'request'
ERROR: /Users/hello/Computer/Development/server/ts_test/functions/src/index.ts[19, 50]: Shadowed name: 'request'

1 个答案:

答案 0 :(得分:1)

您正在使用此导入定义名为request的内容:

import { request } from "https";

然后您要在函数中定义另一个标识符,称为request:

export const helloWorld = functions.https.onRequest((request, response) => {

就目前而言,您将无法在函数内部使用request导入,因为该函数只能看到request参数。

您应该更改其中之一的名称,以使函数中的request不会遮挡(隐藏)导入中的request