在服务 NestJS 中使用时 DTO 不工作
我有一个像 DTO
export class CreatePlotDTO {
@IsNumber()
@ApiProperty()
@IsOptional()
area: number;
@IsNumber()
@ApiProperty()
@IsOptional()
ownerID: number;
}
和一个创建方法 更新:这是在plotService中并接受上面的dto
async createPlot(plot: CreatePlotDTO) {
return this.plotModel.create(plot)
}
这已经工作了最长的时间,但现在因这个错误而失败
Argument of type 'CreatePlotDTO' is not assignable to parameter of type 'CreationAttributes<Plot>'.
Type 'CreatePlotDTO' is not assignable to type 'Omit<any, string>'.
Index signature is missing in type 'CreatePlotDTO'.
我怀疑问题出在“sequelize”:“^ 6.16.2”或“sequelize-typescript” :“^2.1.3”。 有什么想法可以解决这个问题吗?
I have a DTO like
export class CreatePlotDTO {
@IsNumber()
@ApiProperty()
@IsOptional()
area: number;
@IsNumber()
@ApiProperty()
@IsOptional()
ownerID: number;
}
and a create method
UPDATE: this is in the plotService and accepting the dto above
async createPlot(plot: CreatePlotDTO) {
return this.plotModel.create(plot)
}
This has been working for the longest time but now is failing with this error
Argument of type 'CreatePlotDTO' is not assignable to parameter of type 'CreationAttributes<Plot>'.
Type 'CreatePlotDTO' is not assignable to type 'Omit<any, string>'.
Index signature is missing in type 'CreatePlotDTO'.
I suspect the issue is with either "sequelize": "^6.16.2" or "sequelize-typescript": "^2.1.3".
Any ideas to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同样的版本也发生在我身上(“sequelize”:“^ 6.16.2”或“sequelize-typescript”:“^ 2.1.3”)。我怀疑这两者之一出了问题,但作为一种解决方法,我做了如下操作:
注意
部分)。注意
as Plot
部分)。It was happening to me also with the same versions ("sequelize": "^6.16.2" or "sequelize-typescript": "^2.1.3"). I suspect there's something going on with one of those two, but as a workaround, I did something like the following:
(notice the
<Plot>
part).(notice the
as Plot
part).