[英]Error: Tried to select attributes using Sequelize.cast or Sequelize.fn without specifying an alias for the result, during eager loading
[英]Using Sequelize with Typscript result in error
一段时间后,我尝试将我的 NodeJs 应用程序重新开发到 TypeScript,然后我在运行 Sequelize 时遇到了问题。
尝试使用网站上的代码后,出现错误:
This expression is not constructable.
Type 'typeof import("/home/developer/devel/metricsutilities/WorklogMetrics/node_modules/sequelize/types/index")' has no construct signatures.ts(2351)
代码是一个简单的数据库连接器
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()
在一个常见的 JavaScript NodeJS 应用程序中,这是有效的。 Sequelize 6.21.3 在我的新 NodeJS 应用程序中没有。 我认为这与 Sequelize 网站所说的完全一致。 我的新服务器有: Linux Ubuntu 上的节点 16.10.0 Sequelize 6.28.0 @types/sequelize: 4.28.14
我是否错过了构造函数中的某些内容?
您导入整个模块并尝试将其用作 class。只需导入分离的类/函数/枚举/接口,在import
语句中的{}
内枚举它们:
import { Sequelize, Op } from 'sequelize'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.