DEV Community

Cover image for Using ES6 classes for Sequelize 4 models

Using ES6 classes for Sequelize 4 models

Hugo Di Francesco on May 09, 2018

The ES2015 or ES6 specification introduced class to JavaScript. Libraries like React went from React.createClass to class MyComponent extends Rea...
Collapse
 
imsergiobernal profile image
Sergio • Edited

Hello! It is not possible to use super.init() using TypeScript.

class Model<T = any, T2 = any>

The 'this' context of type 'typeof Model' is not assignable to method's 'this' of type 'ModelCtor<Model<unknown, unknown>>'.
  Type 'typeof Model' is not assignable to type 'new () => Model<unknown, unknown>'.
    Cannot assign an abstract constructor type to a non-abstract constructor type.ts(2684)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
64j0 profile image
Vinícius Gajo

You can try using the this.init inside the static method

Collapse
 
marcotterra profile image
Marco

It's possible to do something like this with mongoose ?

Collapse
 
hugo__df profile image
Hugo Di Francesco

From the docs you should be able to do schema.loadClass(MyModel), see mongoosejs.com/docs/4.x/docs/advan...