Skip to content

Commit

Permalink
fix: wrong interface used within mixin (sequelize#13685)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahalwy authored and joe223 committed Nov 22, 2021
1 parent 848217d commit 4587b0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
5 changes: 2 additions & 3 deletions types/lib/associations/belongs-to-many.d.ts
Expand Up @@ -9,8 +9,7 @@ import {
Model,
ModelCtor,
ModelType,
Transactionable,
WhereOptions,
Transactionable
} from '../model';
import { Association, AssociationScope, ForeignKeyOptions, ManyToManyOptions, MultiAssociationAccessors } from './base';

Expand Down Expand Up @@ -304,7 +303,7 @@ export interface BelongsToManyCreateAssociationMixinOptions extends CreateOption
* @see Instance
*/
export type BelongsToManyCreateAssociationMixin<TModel extends Model> = (
values?: Model['_creationAttributes'],
values?: TModel['_creationAttributes'],
options?: BelongsToManyCreateAssociationMixinOptions
) => Promise<TModel>;

Expand Down
4 changes: 2 additions & 2 deletions types/lib/associations/has-many.d.ts
Expand Up @@ -6,7 +6,7 @@ import {
InstanceUpdateOptions,
Model,
ModelCtor,
Transactionable,
Transactionable
} from '../model';
import { Association, ManyToManyOptions, MultiAssociationAccessors } from './base';

Expand Down Expand Up @@ -210,7 +210,7 @@ export interface HasManyCreateAssociationMixinOptions extends CreateOptions<any>
* @see Instance
*/
export type HasManyCreateAssociationMixin<TModel extends Model> = (
values?: Model['_creationAttributes'],
values?: TModel['_creationAttributes'],
options?: HasManyCreateAssociationMixinOptions
) => Promise<TModel>;

Expand Down
20 changes: 9 additions & 11 deletions types/test/typescriptDocs/ModelInit.ts
Expand Up @@ -2,17 +2,9 @@
* Keep this file in sync with the code in the "Usage" section in typescript.md
*/
import {
Sequelize,
Model,
ModelDefined,
DataTypes,
HasManyGetAssociationsMixin,
HasManyAddAssociationMixin,
HasManyHasAssociationMixin,
Association,
HasManyCountAssociationsMixin,
HasManyCreateAssociationMixin,
Optional,
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin, Model,
ModelDefined, Optional, Sequelize
} from "sequelize";

const sequelize = new Sequelize("mysql://root:asd123@localhost:3306/mydb");
Expand Down Expand Up @@ -59,6 +51,7 @@ interface ProjectAttributes {
id: number;
ownerId: number;
name: string;
description?: string;
}

interface ProjectCreationAttributes extends Optional<ProjectAttributes, "id"> {}
Expand Down Expand Up @@ -114,6 +107,10 @@ Project.init(
type: new DataTypes.STRING(128),
allowNull: false,
},
description: {
type: new DataTypes.STRING(128),
allowNull: true,
},
},
{
sequelize,
Expand Down Expand Up @@ -204,6 +201,7 @@ async function doStuffWithUser() {

const project = await newUser.createProject({
name: "first!",
ownerId: 123,
});

const ourUser = await User.findByPk(1, {
Expand Down

0 comments on commit 4587b0b

Please sign in to comment.