Issue
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?
Solution
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:
- Define your model like this:
@Table
export class Plot extends Model<Plot> {
...
}
(notice the <Plot>
part).
- Cast your DTO instance into the actual model type:
async createPlot(plot: CreatePlotDTO) {
return this.plotModel.create(plot as Plot)
}
(notice the as Plot
part).
Answered By - aleclara95
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.