Reputation: 115
I am trying to run sequelize beforeConnect hook to be able to change credential on running sequelize instance. I am literally copy paste what is written in sequelize docs:
https://sequelize.org/master/manual/hooks.html#connection-hooks
this.sequelize = new Sequelize({ config } as SequelizeOptions);
this.sequelize.beforeConnect((config) => {
config.password = "postgres";
})
I am using "sequelize": "6.5.0"
and "sequelize-typescript": "2.1.0"
It is displaying this error:
Property 'beforeConnect' does not exist on type 'Sequelize'. Did you mean to access the static member 'Sequelize.beforeConnect' instead?ts(2576)
And if I try to access it as static method it just does not run
Sequelize.beforeConnect(...)
At least when I use it as a static method it compiles but says that config.password
is a read only. Which is not because the sequalize docs shows exactly this one. Is that just bad types from sequelize-typescript
?
Upvotes: 3
Views: 2042
Reputation: 36
Please see this GitHub link, it helped me to resolve the beforeConnect issue. https://github.com/sequelize/sequelize/issues/12646
The workaround works for me for Sequelize v6.6.2 and Sequelize-typescript v2.1.0.
Upvotes: 2