您好,我不知道在Typescript
中是否可行,但是不可能重载我的Period类的构造函数
不允许使用多个构造函数。ts(2392)
我想做什么:
export class Period {
id: number;
year: string;
month: string;
blocked: boolean;
constructor(id: number, year: string, month: string, blocked: boolean) {
this.id = id;
this.year = year;
this.month = month;
this.blocked = blocked;
}
constructor(year: string, month: string, blocked: boolean) {
this.year = year;
this.month = month;
this.blocked = blocked;
}
}
我希望我可以在插入期间实例化不带ID的Period,例如,对于更新,Period已经具有ID。
我试图在数据库中插入一个null
ID的Period,但这会在Postman上返回错误。
另一方面,如果没有ID参数,它将起作用。
如果有人有解决方案,我很感兴趣。 预先谢谢你。