Skip to content

Commit

Permalink
fix(model): adjust init method to recently introduced sequelize type …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
lukashroch committed Oct 10, 2021
1 parent 1e62c4c commit b60c011
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"prettyjson": "1.2.1",
"reflect-metadata": "0.1.13",
"release-it": "14.11.6",
"sequelize": "6.6.2",
"sequelize": "6.6.5",
"sinon": "11.1.2",
"sinon-chai": "3.7.0",
"source-map-support": "0.5.20",
Expand All @@ -144,6 +144,6 @@
"@types/node": "*",
"@types/validator": "*",
"reflect-metadata": "*",
"sequelize": ">=6.2.0"
"sequelize": ">=6.6.5"
}
}
9 changes: 7 additions & 2 deletions src/model/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type ModelType<TCreationAttributes, TModelAttributes> = new (
options?: any
) => Model<TModelAttributes, TCreationAttributes>;
export type ModelCtor<M extends Model = Model> = Repository<M>;
export type ModelStatic<M extends Model = Model> = { new (): M };

export type $GetType<T> = NonNullable<T> extends any[] ? NonNullable<T> : NonNullable<T> | null;

Expand All @@ -36,11 +37,15 @@ export abstract class Model<

static isInitialized = false;

static init(attributes: ModelAttributes, options: InitOptions): Model {
public static initialize<MS extends ModelStatic<Model>, M extends InstanceType<MS>>(
attributes: ModelAttributes,
options: InitOptions
): MS {
this.isInitialized = true;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return super.init(attributes, options);
return super.init<MS, M>(attributes, options);
}

constructor(values?: TCreationAttributes, options?: BuildOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/sequelize/sequelize/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Sequelize extends OriginSequelize {
};
const definedModel = this.repositoryMode ? this.createRepositoryModel(model) : model;

definedModel.init(attributes, initOptions);
definedModel.initialize(attributes, initOptions);

return definedModel;
});
Expand Down

0 comments on commit b60c011

Please sign in to comment.