Having previous experience with Sequelize for projects (v4), I am now venturing into starting a new project using Sequelize v5 & Typescript.
I have been following Sequelize's documentation on how to define Models at: https://sequelize.org/master/manual/typescript.html#usage-of--code-sequelize-define--code-
Currently, I have successfully set up an ORM, but only when importing the actual model for use, not through importing the db from the model loader. For example:
import { User } from "../db/models/user";
When trying to access db.User after importing the db, I just get back undefined.
I am currently struggling to find a way to make the model loader work seamlessly with Sequelize V5 and Typescript.
It seems like the system is looking for .js files, which explains why it doesn't recognize the user.ts file. However, changing it to .ts gives me the following error...
... (error message)
Despite my efforts in researching online, I have yet to find a clear answer. Dealing with getting everything aligned properly has been quite a challenge. At this point, I am running migrations/seeders as js files to avoid dealing with sequelize-typescript-cli or sequelize-typescript.
src/db/models/user.ts
User Model
...(user model code as shown in original text)...
src/db/models/index.ts
Model Loader
...(model loader code as shown in original text)...
Additionally, the documentation at https://sequelize.org/master/manual/typescript.html#usage provides some insights on defining models in a clearer but slightly more redundant manner. My concern now is how the 'init' method is called during the initialization of Sequelize from index.js?