Skip to content

Commit

Permalink
fix(types): return a usable type when using the sequelize.models look…
Browse files Browse the repository at this point in the history
…up (#11293)
  • Loading branch information
schmod authored and sushantdhiman committed Aug 9, 2019
1 parent 98a4089 commit a39c63a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions types/lib/sequelize.d.ts
Expand Up @@ -19,6 +19,7 @@ import {
UpdateOptions,
WhereAttributeHash,
WhereOperators,
ModelCtor,
} from './model';
import { ModelManager } from './model-manager';
import * as Op from './operators';
Expand Down Expand Up @@ -767,7 +768,7 @@ export class Sequelize extends Hooks {
* Dictionary of all models linked with this instance.
*/
public readonly models: {
[key: string]: typeof Model;
[key: string]: ModelCtor<Model>;
};

/**
Expand Down Expand Up @@ -1109,7 +1110,7 @@ export class Sequelize extends Hooks {
*
* @param modelName The name of a model defined with Sequelize.define
*/
public model(modelName: string): typeof Model;
public model(modelName: string): ModelCtor<Model>;

/**
* Checks whether a model with the given name is defined
Expand Down
6 changes: 5 additions & 1 deletion types/test/sequelize.ts
Expand Up @@ -49,4 +49,8 @@ Sequelize.afterConnect(() => {

const rnd: Fn = sequelize.random();

const myModel: typeof Model = sequelize.models.asd;
class Model1 extends Model{}
class Model2 extends Model{}
const myModel: typeof Model1 = sequelize.models.asd;
myModel.hasOne(Model2)
myModel.findAll();

0 comments on commit a39c63a

Please sign in to comment.