Home > Blockchain >  Using Sequelize with Typscript result in error
Using Sequelize with Typscript result in error

Time:01-30

After some time I try to re-develop my NodeJs app to TypeScript and I run with Sequelize into problems.

After trying to use the code from the website, I get an error:

This expression is not constructable.
  Type 'typeof import("/home/developer/devel/metricsutilities/WorklogMetrics/node_modules/sequelize/types/index")' has no construct signatures.ts(2351)

The code is a simple database connector

import * as Sequelize from 'sequelize'

export const sequelize = new Sequelize("xx", "xxx", "xxx", {
  host: "xxx",
  dialect: "postgres",
  pool: {
    max: 15,
    min: 0,
    idle: 10000,
  },
  logging: false,
  timezone: " 01:00",
});
sequelize.authenticate()

Inside a common JavaScript NodeJS app this is working. Sequelize 6.21.3 Inside my new NodeJS app not. And I think it is exact the Sequelize website says. My new server has: Node 16.10.0 on Linux Ubuntu Sequelize 6.28.0 @types/sequelize: 4.28.14

Do I miss something inside the constructor?

CodePudding user response:

You import the whole module and tried to use it as a class. Just import separated classes/functions/enums/interfaces enumerating them inside {} in the import statement:

import { Sequelize, Op } from 'sequelize'
  • Related