Currently, I am tackling a legacy project with the goal of transitioning it to Typescript. The project contains models that are structured as shown below:
import Sequelize from "sequelize";
class MyModel extends Sequelize.Model {
public static init(sequelize) {
const attributes = {
userId: {
type: Sequelize.INTEGER,
allowNull: false,
field: "user_id"
},
createdAt: {
type: Sequelize.DATE,
field: "created_at"
}
};
super.init(attributes, {
sequelize
});
}
}
export default MyModel;
My objective is to convert these models to Typescript without altering the interface for consumers. Specifically, I aim to extend Sequelize.Model
and define a public static init
method.
However, when attempting this migration, I encounter the following error in Typescript related to Sequelize.Model
:
Type 'Model<any, any>' is not a constructor function type.
All my research indicates that I should be using Sequelize.define
for defining models.
Considering the nature of this being a legacy project, rewriting all the models just to fit the types seems impractical. Therefore, I am seeking guidance on how to effectively extend Sequelize.Model
.
Thank you.