From c7b2669764b37208c787e8586366d83e1593f5e4 Mon Sep 17 00:00:00 2001 From: Andrew Schmadel Date: Wed, 7 Aug 2019 10:10:55 -0400 Subject: [PATCH] fix(types): return a usable type when using the sequelize.models lookup --- types/lib/sequelize.d.ts | 5 +++-- types/test/sequelize.ts | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/types/lib/sequelize.d.ts b/types/lib/sequelize.d.ts index cf517bcc707e..7740d88680ae 100644 --- a/types/lib/sequelize.d.ts +++ b/types/lib/sequelize.d.ts @@ -19,6 +19,7 @@ import { UpdateOptions, WhereAttributeHash, WhereOperators, + ModelCtor, } from './model'; import { ModelManager } from './model-manager'; import * as Op from './operators'; @@ -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; }; /** @@ -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; /** * Checks whether a model with the given name is defined diff --git a/types/test/sequelize.ts b/types/test/sequelize.ts index a01d57925cdd..216db5b181cc 100644 --- a/types/test/sequelize.ts +++ b/types/test/sequelize.ts @@ -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(); \ No newline at end of file