Sequelize-typescript: Missing properties in create/build ($add, $set, $get, $count, and 32 more).

Created on 6 Mar 2021  路  6Comments  路  Source: RobinBuschmann/sequelize-typescript

Issue

Versions

  • sequelize: 6.5.0
  • sequelize-typescript: 2.1.0
  • typescript: 4.2.3

Issue type

  • [x] bug report
  • [ ] feature request

Actual behavior

Model.create({value1: ""}) fails because $add, $set, $get, $count, and 32 more properties are missing.

Expected behavior

The instance of the model is created with the specified values.

Steps to reproduce

Open the related code-repository, open the lib/routes/actors.ts file, it should show a type error.

Related code

https://github.com/sleiss/sequelize-typescript-example

Error in related code:

lib/routes/actors.ts (8,38): Argument of type '{ firstName: string; lastName: string; }' is not assignable to parameter of type 'Actor'.
  Type '{ firstName: string; lastName: string; }' is missing the following properties from type 'Actor': $add, $set, $get, $count, and 32 more. (2345)

Most helpful comment

@sleiss, you probably want to declare models like this: https://github.com/RobinBuschmann/sequelize-typescript#model-definition

your example code is using export class Actor extends Model<Actor>, which is definition for sequelize v5 & sequelize-ts v1.

All 6 comments

same problem. my solution is:

const application = await this.applicationRepository.create<Application>(
      ({
        id: Math.random().toString(32),
        createdAt: new Date(),
        updatedAt: new Date(),
        ...createApplicationDto,
      } as any) as Application,
      { transaction },
    );

but this cannot utilizes typescript features anymore. hope someone can give a better solution.

I met the same problem, do you have a better plan?

same here

@sleiss, you probably want to declare models like this: https://github.com/RobinBuschmann/sequelize-typescript#model-definition

your example code is using export class Actor extends Model<Actor>, which is definition for sequelize v5 & sequelize-ts v1.

@lukashroch This indeed seems to fix the issue.
I'll validate it now.

@lukashroch Thanks, it fixed the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zebkailash picture zebkailash  路  4Comments

josecolella picture josecolella  路  4Comments

ReneHollander picture ReneHollander  路  3Comments

lilling picture lilling  路  4Comments

fareshan picture fareshan  路  3Comments