Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 98a40891
authored
Aug 09, 2019
by
Andrew Schmadel
Committed by
Sushant
Aug 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(types): use correct `this` value in getterMethods and setterMethods (#11292)
1 parent
dd428a06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
types/lib/model.d.ts
types/test/model.ts
types/lib/model.d.ts
View file @
98a4089
...
@@ -1178,15 +1178,15 @@ export interface ModelNameOptions {
...
@@ -1178,15 +1178,15 @@ export interface ModelNameOptions {
/**
/**
* Interface for getterMethods in InitOptions
* Interface for getterMethods in InitOptions
*/
*/
export
interface
ModelGetterOptions
{
export
interface
ModelGetterOptions
<
M
extends
Model
=
Model
>
{
[
name
:
string
]:
(
this
:
M
odel
)
=>
unknown
;
[
name
:
string
]:
(
this
:
M
)
=>
unknown
;
}
}
/**
/**
* Interface for setterMethods in InitOptions
* Interface for setterMethods in InitOptions
*/
*/
export
interface
ModelSetterOptions
{
export
interface
ModelSetterOptions
<
M
extends
Model
=
Model
>
{
[
name
:
string
]:
(
this
:
M
odel
,
val
:
any
)
=>
void
;
[
name
:
string
]:
(
this
:
M
,
val
:
any
)
=>
void
;
}
}
/**
/**
...
@@ -1477,12 +1477,12 @@ export interface ModelOptions<M extends Model = Model> {
...
@@ -1477,12 +1477,12 @@ export interface ModelOptions<M extends Model = Model> {
/**
/**
* Allows defining additional setters that will be available on model instances.
* Allows defining additional setters that will be available on model instances.
*/
*/
setterMethods
?:
ModelSetterOptions
;
setterMethods
?:
ModelSetterOptions
<
M
>
;
/**
/**
* Allows defining additional getters that will be available on model instances.
* Allows defining additional getters that will be available on model instances.
*/
*/
getterMethods
?:
ModelGetterOptions
;
getterMethods
?:
ModelGetterOptions
<
M
>
;
/**
/**
* Enable optimistic locking.
* Enable optimistic locking.
...
@@ -1498,7 +1498,7 @@ export interface ModelOptions<M extends Model = Model> {
...
@@ -1498,7 +1498,7 @@ export interface ModelOptions<M extends Model = Model> {
/**
/**
* Options passed to [[Model.init]]
* Options passed to [[Model.init]]
*/
*/
export
interface
InitOptions
extends
ModelOptions
{
export
interface
InitOptions
<
M
extends
Model
=
Model
>
extends
ModelOptions
<
M
>
{
/**
/**
* The sequelize connection. Required ATM.
* The sequelize connection. Required ATM.
*/
*/
...
@@ -1588,7 +1588,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
...
@@ -1588,7 +1588,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
* string or a type-description object, with the properties described below:
* string or a type-description object, with the properties described below:
* @param options These options are merged with the default define options provided to the Sequelize constructor
* @param options These options are merged with the default define options provided to the Sequelize constructor
*/
*/
public
static
init
(
attributes
:
ModelAttributes
,
options
:
InitOptions
):
void
;
public
static
init
<
M
extends
Model
=
Model
>
(
this
:
ModelCtor
<
M
>
,
attributes
:
ModelAttributes
,
options
:
InitOptions
<
M
>
):
void
;
/**
/**
* Remove attribute from model definition
* Remove attribute from model definition
...
...
types/test/model.ts
View file @
98a4089
...
@@ -38,11 +38,16 @@ MyModel.init({}, {
...
@@ -38,11 +38,16 @@ MyModel.init({}, {
}
}
],
],
sequelize
,
sequelize
,
tableName
:
'my_model'
tableName
:
'my_model'
,
getterMethods
:
{
multiply
:
function
()
{
return
this
.
num
*
2
;
}
}
});
});
/**
/**
* Tests for findCreateFind() type.
* Tests for findCreateFind() type.
*/
*/
class
UserModel
extends
Model
{}
class
UserModel
extends
Model
{}
...
@@ -56,9 +61,9 @@ UserModel.init({
...
@@ -56,9 +61,9 @@ UserModel.init({
UserModel
.
findCreateFind
({
UserModel
.
findCreateFind
({
where
:
{
where
:
{
username
:
"new user username"
username
:
"new user username"
},
},
defaults
:
{
defaults
:
{
beta_user
:
true
beta_user
:
true
}
}
})
})
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment