fix(typings): model init returns model class, not instance (#13214) · sequelize/sequelize@8f2a0d5

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1622,10 +1622,10 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut

16221622

* @param options These options are merged with the default define options provided to the Sequelize constructor

16231623

* @return Return the initialized model

16241624

*/

1625-

public static init<M extends Model>(

1626-

this: ModelStatic<M>,

1625+

public static init<MS extends ModelStatic<Model>, M extends InstanceType<MS>>(

1626+

this: MS,

16271627

attributes: ModelAttributes<M, M['_attributes']>, options: InitOptions<M>

1628-

): Model;

1628+

): MS;

16291629
16301630

/**

16311631

* Remove attribute from model definition

Original file line numberDiff line numberDiff line change

@@ -52,7 +52,7 @@ MyModel.update({}, { where: { foo: 'bar' }, paranoid: false});

5252
5353

const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');

5454
55-

MyModel.init({

55+

const model: typeof MyModel = MyModel.init({

5656

virtual: {

5757

type: new DataTypes.VIRTUAL(DataTypes.BOOLEAN, ['num']),

5858

get() {