wangduanduan / wangduanduan.github.io

Wubba Lubba dub-dub
https://wdd.js.org
27 stars 7 forks source link

sequelize: Cannot use 'new' with an expression whose type lacks a call or construct signature.ts(2351) #296

Closed wangduanduan closed 5 years ago

wangduanduan commented 5 years ago

已经安装了

"sequelize": "^5.8.6",
"@types/sequelize": "^4.27.49",

使用db.ts, 下面的写法,还是报错

Cannot use 'new' with an expression whose type lacks a call or construct signature.ts(2351)
import Sequelize from 'sequelize'

const sequelize = new Sequelize('db', 'username', 'pass', {
  host: 'localhost',
  dialect: 'mysql'
})
wangduanduan commented 5 years ago

打开@types/sequelize里面的源码,发现原来@types/sequelize只支持4.x版本的Sequelize,5.x版本的Sequelize是自带定义文件的。

// ***************************** IMPORTANT NOTE *****************************
// These types are for the 4.x branch of Sequelize. As of Sequelize 5.0,
// types are packaged directly within Sequelize itself. Please target the
// Sequelize-provided types for any changes related to versions >= 5.0.
wangduanduan commented 5 years ago

具体参考 官方教程 http://docs.sequelizejs.com/manual/typescript