Cannot use my models in sequelize typescript

200 views Asked by At

I am trying to initialise my 'User' model in sequelize:

import { User } from "./models/User";
import { Sequelize } from "sequelize";

private async connectToPostgreSQL() {
this.sequelize = new Sequelize({
  database: this.POSTGRES_DB,
  username: this.POSTGRES_USER,
  password: this.POSTGRES_PASSWORD,
  host: this.POSTGRES_HOST,
  port: this.POSTGRES_PORT,
  dialect: "postgres",
  models: [User]
});

But im always get an error:

No overload matches this call. Overload 1 of 4, '(options?: Options | undefined): Sequelize', gave the following error. Argument of type '{ database: string; username: string; password: string; host: string; port: number; dialect: "postgres"; models: any[]; }' is not assignable to parameter of type 'Options'. Object literal may only specify known properties, and 'models' does not exist in type 'Options'. Overload 2 of 4, '(uri: string, options?: Options | undefined): Sequelize', gave the following error. Argument of type '{ database: string; username: string; password: string; host: string; port: number; dialect: string; models: any[]; }' is not assignable to parameter of type 'string'.ts(2769

What i can do to add my custom modal into serialize?

Versions:

"sequelize": "^6.34.0",
"sequelize-typescript": "^2.1.5"
1

There are 1 answers

0
jQueeny On

You need to import the Sequelize class from sequelize-typescript. Those parameters in that order are from the sequelize-typescript module.

//import { Sequelize } from "sequelize"; //< Delete this
import { Sequelize } from "sequelize-typescript"; //< Add this