So I finally decided to try out TypeScript, because of everything I've heard about it and how having static types is good for me. I decided to test it out by creating a simple web API with sequelize, but I am having trouble understanding the types returned from sequelize. So I have the following imports (note that I've also installed the @types/sequelize npm module:
import sequelize = require('sequelize');
import {DataTypes} from 'sequelize';
I am creating my model like this:
const User:sequelize.Model= db.define('User',{
id: {type:DataTypes.INTEGER, primaryKey:true},
email:{type:DataTypes.STRING, allowNull:false},
hashedPassword:{type:DataTypes.STRING,allowNull:false}
});
But I am getting this error:
Type 'ModelCtor<Model<any, any>>' is missing the following properties from type 'Model<any,any>': _attributes, _creationAttributes, isNewRecord, where, and 16 more.
But if I do this:
const User:any= db.define('User',{
id: {type:DataTypes.INTEGER, primaryKey:true},
email:{type:DataTypes.STRING, allowNull:false},
hashedPassword:{type:DataTypes.STRING,allowNull:false}
});
It works fine. But of course, because this is TypeScript, I want to take advantage of Types. Using "any" defeats the purpose. How can I know which type I should use for my model? Unfortunately, most of sequelize's documentation is regular javascript, so I can't find examples of this. Any help is appreciated.