-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): improve ModelCtor / ModelStatic typing (#13890)
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Model, Optional, DataTypes } from 'sequelize'; | ||
import { sequelize } from '../connection'; | ||
|
||
export interface UserPostAttributes { | ||
id: number; | ||
userId: number; | ||
text: string; | ||
} | ||
|
||
export interface UserPostCreationAttributes | ||
extends Optional<UserPostAttributes, 'id'> {} | ||
|
||
export interface UserPostInstance | ||
extends Model<UserPostAttributes, UserPostCreationAttributes>, | ||
UserPostAttributes {} | ||
|
||
/** | ||
* This is a component defined using `sequelize.define` to ensure that various | ||
* functions also work with non-class models, which were the default before | ||
* Sequelize v5. | ||
*/ | ||
export const UserPost = sequelize.define<UserPostInstance>( | ||
'UserPost', | ||
{ | ||
id: { | ||
type: DataTypes.INTEGER.UNSIGNED, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
userId: { | ||
type: DataTypes.INTEGER.UNSIGNED, | ||
allowNull: false, | ||
}, | ||
text: { | ||
type: DataTypes.STRING(255), | ||
allowNull: false, | ||
}, | ||
}, | ||
{ | ||
indexes: [ | ||
{ | ||
name: 'userId', | ||
fields: ['userId'], | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
UserPost.findOne({ where: { id: 1 }}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters