我正在尝试在typescript中使用Google Cloud function (GCF)来设置NodeJS函数。我试图严格执行我的代码,它要求定义所有参数,在这种情况下,需要定义(req, res)参数。
我知道GCF在幕后使用Express,但我不认为我需要因为它而导入Express。是否有任何最佳实践或文档来解释如何在GCF中使用typescript?
我尝试使用@google-cloud/functions-framework包,发现有一些有用的接口或类可以使用,但我无法确定函数的起点应该是什么。
import GCF from '@google-cloud/functions-framework';
export const startFunction = ((req: GCF.???, res: GCF.???)): void => {
// additional work done here
}任何帮助都是非常感谢的。
发布于 2020-06-27 01:52:39
看起来最新的@google-cloud/functions-framework现在包含了函数签名。
// Start writing Cloud Functions
// https://cloud.google.com/functions/docs/writing/http
import { HttpFunction } from '@google-cloud/functions-framework/build/src/functions';
export const helloHttp: HttpFunction = (req, res) => {
res.send(`Hello World`);
};https://stackoverflow.com/questions/58098852
复制相似问题