TypeScript

    • (this is universally required)
    • @types/validator
    • @types/bluebird
    1. // We need to declare an interface for our model that is basically what our class would be
    2. interface MyModel extends Model {
    3. readonly id: number;
    4. }
    5. // Need to declare the static model so `findOne` etc. use correct types.
    6. new (values?: object, options?: BuildOptions): MyModel;
    7. }
    8. // TS can't derive a proper class definition from a `.define` call, therefor we need to cast here.
    9. const MyDefineModel = <MyModelStatic>sequelize.define('MyDefineModel', {
    10. id: {
    11. primaryKey: true,
    12. type: DataTypes.INTEGER.UNSIGNED,
    13. function stuffTwo() {
    14. MyDefineModel.findByPk(1, {
    15. rejectOnEmpty: true,
    16. })
    17. .then(myModel => {
    18. console.log(myModel.id);
    19. });