Как решить ошибку error TS2345: Argument of type 'CreateRoleDto' is not assignable to parameter?
файл create-role.dto
export class CreateRoleDto {
readonly value: String;
readonly description: String;
}
файл roles.service.ts
import { Injectable } from '@nestjs/common';
import { CreateRoleDto } from './dto/create-role.dto';
import { InjectModel } from '@nestjs/sequelize';
import { Role } from './roles.model';
@Injectable()
export class RolesService {
constructor (@InjectModel(Role) private roleRepository: typeof Role) {}
async createRole(dto: CreateRoleDto) {
const role = await this.roleRepository.create(dto);
return role;
}
async getRoleByValue (value: string) {
const role = await this.roleRepository.findOne({where: {value}})
return role;
}
}
ошибка
error TS2345: Argument of type 'CreateRoleDto' is not assignable to parameter of type 'Optional<RoleCreationAttrs, NullishPropertiesOf<RoleCreationAttrs>>'.
Type 'CreateRoleDto' is not assignable to type 'Partial<Pick<RoleCreationAttrs, NullishPropertiesOf<RoleCreationAttrs>>>'.
файл roles.model.ts
import { ApiProperty } from "@nestjs/swagger";
import { BelongsToMany } from "sequelize-typescript";
import { Column, DataType, Model, Table } from "sequelize-typescript";
import { Users } from "src/users/users.model";
import { UserRoles } from "./user-roles.model";
interface RoleCreationAttrs {
value: string;
description: string;
}
@Table({tableName: 'roles'})
export class Role extends Model<Role, RoleCreationAttrs> {
@ApiProperty({example: '1', description: 'User unique Id number'})
@Column({type: DataType.INTEGER, unique: true, autoIncrement: true, primaryKey: true})
id: number;
@ApiProperty({example: 'Admin/Moder/User', description: 'Role unique value'})
@Column({type: DataType.STRING, unique: true, allowNull: false})
value: string;
@ApiProperty({example: 'Short desc', description: 'Short description of role'})
@Column({type: DataType.STRING, allowNull: false})
description: string;
@BelongsToMany(() => Users, () => UserRoles)
users: Users[];
}