3

I used the below configuration to generate models

const auto = new SequelizeAuto(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
  host: process.env.DB_HOST,
  dialect: 'mysql',
  typescript: true,
  camelCaseForFileName: true,
  directory: './src/data/entity'
})
auto.run();

But i'm getting error on Models generated Cannot use namespace 'DataTypes' as a type.ts(2709)

Error Message

FYR i also raised an issue GitHub repository: https://github.com/sequelize/sequelize-auto/issues/384

anjnkmr
  • 838
  • 15
  • 37
  • This doesn't seem like how you should be using Sequelize with Typescript... Please check here: https://sequelize.org/master/manual/typescript – ionizer Nov 01 '19 at 22:57
  • i'm using `sequelize-auto` package to generate models, but these are giving errors i checked the link, but i want to generate the models – anjnkmr Nov 04 '19 at 12:32
  • Current version (0.7.5) of `sequelize-auto` generates TypeScript according to the guidance in the Sequelize manual. – Steve Schmitt Dec 05 '20 at 19:06

1 Answers1

3

In my case, changing the auto-generated code from

module.exports =  (sequelize: Sequelize, DataTypes: DataTypes)

to

module.exports =  (sequelize: Sequelize, dataTypes: typeof DataTypes) 

resolved that error.

elirandav
  • 1,913
  • 19
  • 27
  • thanks for the update. I have updated my plugin to latest version for both sequelize & sequelize-auto, Latest version of sequelize-auto has more options than earlier – anjnkmr Apr 15 '21 at 05:07