打字稿将值传递给日期验证装饰器?

Typescript passing values to Date Validation Decorators?

我正在尝试验证这样的日期(购买日期和收货日期都是 class 属性):

@IsDate()
@MinDate(date: this.purchaseDate)
receiptDate: Date;

但是我收到以下错误:

src/main/ts/domain/PurchaseOrder.ts(20,16):错误 TS1005:预期为“,”。 src/main/ts/domain/PurchaseOrder.ts(20,12):错误 TS2304:找不到名称 'date'.

购买日期标注约束应该如何传递?注释来自 class-validator 库。

您使用的语法错误。看起来您正在尝试定义类型为 this.purchaseDate 的函数。

您只需将 this.purchaseDate 作为参数发送即可。

@MinDate(this.purchaseDate)