我正在尝试在打字稿中使用 Google Cloud Function (GCF) 设置 NodeJS 函数。我试图对我的代码严格要求,它需要定义所有参数,在这种情况下(req, res)需要定义参数。
我知道 GCF 在底层使用 Express,但我认为我不需要因此导入 Express。是否有任何最佳实践或文档解释如何将 typescript 与 GCF 结合使用?
我尝试使用该@google-cloud/functions-framework包并发现有任何有用的接口或类可供使用,但我无法确定该函数的起点应该是什么。
import GCF from '@google-cloud/functions-framework';
export const startFunction = ((req: GCF.???, res: GCF.???)): void => {
// additional work done here
}
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏。
我要创建一个大型表单,并决定使用反应式表单功能以方便使用。然而,我面临着一些可能显而易见的挑战并寻求帮助。
下面是两种情况,除了验证之外,它们产生相同的结果。该createFormWithValidation()方法指定了每个控件及其关联的验证器。该方法仅使用对象但不添加验证器createFromPassingObject()来创建相同的表单。this.party
我的目标是将一个对象传递给this.fb.group()该对象,该对象将具有属于该类的控件,并且能够为该类的每个属性指定验证器Party。
// The Class with the properties
export class Party {
firstName: string = '';
lastName: string = '';
constructor() {}
}
// party Object
myForm: FormGroup;
this.party = new Party();
// Form with explicit controls and their validators
createFormWithValidation() {
this.myForm = this.fb.group({
firstName: [this.party.firstName, [Validators.required, Validators.minLength(3)]],
lastName: [this.party.lastName, [Validators.required, Validators.minLength(3)]]
})
}
// The goal is to achieve this type of method where this.party will be the …Run Code Online (Sandbox Code Playgroud)