Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): return a usable type when using the sequelize.models lookup #11293

Merged
merged 1 commit into from Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
papb marked this conversation as resolved.
Show resolved Hide resolved
class Model1 extends Model{}
class Model2 extends Model{}
const myModel: typeof Model1 = sequelize.models.asd;
myModel.hasOne(Model2)
myModel.findAll();