mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
Merge pull request #28294 from henrikra/master
[sequelize] Improve type safety when using define
This commit is contained in:
Vendored
+15
-1
@@ -4672,6 +4672,20 @@ declare namespace sequelize {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for Attributes provided for a column
|
||||
*
|
||||
* @see Sequelize.define
|
||||
*/
|
||||
type DefineModelAttributes<T> = {
|
||||
|
||||
/**
|
||||
* The description of a database column for model
|
||||
*/
|
||||
[P in keyof T]: string | DataTypeAbstract | DefineAttributeColumnOptions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for query options
|
||||
*
|
||||
@@ -5976,7 +5990,7 @@ declare namespace sequelize {
|
||||
* @param options These options are merged with the default define options provided to the Sequelize
|
||||
* constructor
|
||||
*/
|
||||
define<TInstance, TAttributes>(modelName: string, attributes: DefineAttributes,
|
||||
define<TInstance, TAttributes>(modelName: string, attributes: DefineModelAttributes<TAttributes>,
|
||||
options?: DefineOptions<TInstance>): Model<TInstance, TAttributes>;
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,11 +34,16 @@ s.transaction().then( ( a ) => t = a );
|
||||
interface GUserAttributes {
|
||||
id? : number;
|
||||
username? : string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
interface GUserInstance extends Sequelize.Instance<GUserAttributes> {}
|
||||
var GUser = s.define<GUserInstance, GUserAttributes>( 'user', { id: Sequelize.INTEGER, username : Sequelize.STRING });
|
||||
GUser.create({ id : 1, username : 'one' }).then( ( guser ) => guser.save() );
|
||||
const GUser = s.define<GUserInstance, GUserAttributes>('user', {
|
||||
id: Sequelize.INTEGER,
|
||||
username: Sequelize.STRING,
|
||||
email: Sequelize.STRING
|
||||
});
|
||||
GUser.create({ id : 1, username : 'one', email: 'one@lol.com' }).then((guser) => guser.save());
|
||||
|
||||
var schema : Sequelize.DefineAttributes = {
|
||||
key : { type : Sequelize.STRING, primaryKey : true },
|
||||
@@ -1294,7 +1299,7 @@ var testModel = s.define( 'User', {
|
||||
theDate : Sequelize.DATE,
|
||||
aBool : Sequelize.BOOLEAN
|
||||
} );
|
||||
var testModel = s.define( 'FrozenUser', {}, { freezeTableName : true } );
|
||||
const testFrozenModel = s.define( 'FrozenUser', {}, { freezeTableName : true } );
|
||||
s.define( 'UserWithClassAndInstanceMethods', {}, {
|
||||
classMethods : { doSmth : function() { return 1; } },
|
||||
instanceMethods : { makeItSo : function() { return 2; } }
|
||||
@@ -1539,7 +1544,11 @@ interface ChairAttributes {
|
||||
}
|
||||
interface ChairInstance extends Sequelize.Instance<ChairAttributes> {}
|
||||
|
||||
const Chair = s.define<ChairInstance, ChairAttributes>('chair', {});
|
||||
const Chair = s.define<ChairInstance, ChairAttributes>('chair', {
|
||||
id: Sequelize.NUMBER,
|
||||
color: Sequelize.STRING,
|
||||
legs: Sequelize.NUMBER
|
||||
});
|
||||
|
||||
Chair.findAll({
|
||||
where: {
|
||||
@@ -1728,7 +1737,7 @@ s.define('DefineOptionsIndexesTest', {
|
||||
email: {
|
||||
allowNull: false,
|
||||
type: Sequelize.STRING(255),
|
||||
set: function (val) {
|
||||
set: function (val: any) {
|
||||
if (typeof val === "string") {
|
||||
val = val.toLowerCase();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user