![](/img/trans.png)
[英]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.