Skip to content

Commit

Permalink
Fix ModelCtor definition
Browse files Browse the repository at this point in the history
  • Loading branch information
KapitanOczywisty committed Feb 7, 2021
1 parent 164e658 commit c65f875
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/model/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {AssociationGetOptions} from "./association/association-get-options";
import {AssociationCountOptions} from "./association/association-count-options";
import {AssociationActionOptions} from "./association/association-action-options";
import {AssociationCreateOptions} from "./association/association-create-options";
import {Repository} from '../../sequelize/repository/repository';

export type ModelType<TCreationAttributes, TModelAttributes> = new (values?: TCreationAttributes, options?: any) => Model<TModelAttributes, TCreationAttributes>;
export type ModelCtor<M extends Model = Model> = (new () => M) & typeof Model;
export type ModelCtor<M extends Model = Model> = Repository<M>;

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

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 @@ -110,7 +110,7 @@ export class Sequelize extends OriginSequelize {
}

private createRepositoryModel(modelClass: ModelCtor): ModelCtor {
return class extends modelClass<any> {
return class extends modelClass {
};
}

Expand Down
9 changes: 9 additions & 0 deletions test/types/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
BelongsTo,
BelongsToMany,
ForeignKey,
PrimaryKey,
Sequelize,
} from "../../src/index";
import { Column } from "../../src/model/column/column";
import { Model } from "../../src/model/model/model";
Expand Down Expand Up @@ -36,6 +38,7 @@ type PersonCreationAttributes = Optional<PersonAttributes, "id">;

@Table
export class Person extends Model<PersonAttributes, PersonCreationAttributes> {
@PrimaryKey
@AutoIncrement
@Column(DataType.INTEGER)
id: number;
Expand All @@ -46,6 +49,7 @@ export class Person extends Model<PersonAttributes, PersonCreationAttributes> {

@Table
export class Pet extends Model {
@PrimaryKey
@AutoIncrement
@Column(DataType.INTEGER)
petId: number;
Expand All @@ -71,3 +75,8 @@ export class Toy extends Model {
@BelongsTo(() => Pet)
pet: Pet;
}

function testTypes() {
// all models should be accepted
new Sequelize().addModels([Person, Pet, PetPerson]);
}

0 comments on commit c65f875

Please sign in to comment.