Sequelize-typescript: Error when defining relationships (BelongsTo, ForeignKey, HasMany etc)

Created on 29 Jul 2020  路  5Comments  路  Source: RobinBuschmann/sequelize-typescript

Versions

  • sequelize: ^6.3.3
  • sequelize-typescript: ^1.1.0
  • typescript: ^3.9.7

I'm submitting a ...

[x ] bug report
[ ] feature request

Actual behavior:
I'm getting a type error when I try and define a relationship between Models

Expected behavior:
Being able to define relationships as per the docs and examples

Related code:
Screenshot 2020-07-29 at 15 40 12
Screenshot 2020-07-29 at 15 49 25
Screenshot 2020-07-29 at 15 49 39
Screenshot 2020-07-29 at 15 56 36
Screenshot 2020-07-29 at 15 56 47

Most helpful comment

Same here, a fix would be great

All 5 comments

Hi @Evanion, this is the same issue at lot of people are having here. I have commented on issue #813 this:

I have this same issue. Could resolve this by removing the type constructor (<Questions>, <Options>).

In my case I had a QuestionsAttributes interface and had to change:

class TalentData extends Model<TalentData, TalentDataAttributes>

to:

class TalentData extends Model implements TalentDataAttributes

But this really appears to be a sequelize-typescript error.

@RobinBuschmann any thoughts on that?

I had this same issue this morning and cross-compared my current project against one that was still working. I noticed I had a few modules with later versions, especially Typescript, Sequelize itself, and some of the @types incudes, so I downgraded them and this resolved the problem.

For reference, this is working for me. Later versions of Sequelize and other deps are not:

  "dependencies": {
    "mysql2": "^2.1.0",
    "reflect-metadata": "^0.1.13",
    "sequelize": "^5.22.2",
    "sequelize-typescript": "^1.1.0"
  },
  "devDependencies": {
    "@types/sequelize": "^4.28.9",
    "@types/bluebird": "^3.5.32",
    "@types/validator": "^13.0.0",
    "@types/node": "^14.0.13",
    "typescript": "^3.9.5"
  },

Yeah, having similar issue. Downgraded from v 6 to "sequelize": "^5.22.2" and error disappeared.

+1 Getting the same error. Downgrading to 5.22.2 also resolved the issue for me.

Same here, a fix would be great

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bschveitzer picture bschveitzer  路  5Comments

KAMAELUA picture KAMAELUA  路  4Comments

ReneHollander picture ReneHollander  路  3Comments

JustGreg picture JustGreg  路  4Comments

fareshan picture fareshan  路  3Comments