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 afb8cc34
authored
Nov 09, 2019
by
Ariel Barabas
Committed by
Sushant
Nov 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(types): specified 'this' for getters and setters in fields (#11648)
1 parent
21978ebe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
types/lib/model.d.ts
types/test/model.ts
types/lib/model.d.ts
View file @
afb8cc3
...
@@ -1260,7 +1260,7 @@ export interface ModelAttributeColumnReferencesOptions {
...
@@ -1260,7 +1260,7 @@ export interface ModelAttributeColumnReferencesOptions {
/**
/**
* Column options for the model schema attributes
* Column options for the model schema attributes
*/
*/
export
interface
ModelAttributeColumnOptions
extends
ColumnOptions
{
export
interface
ModelAttributeColumnOptions
<
M
extends
Model
=
Model
>
extends
ColumnOptions
{
/**
/**
* A string or a data type
* A string or a data type
*/
*/
...
@@ -1341,23 +1341,23 @@ export interface ModelAttributeColumnOptions extends ColumnOptions {
...
@@ -1341,23 +1341,23 @@ export interface ModelAttributeColumnOptions extends ColumnOptions {
* Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying
* Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying
* values.
* values.
*/
*/
get
?():
unknown
;
get
?(
this
:
M
):
unknown
;
/**
/**
* Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the
* Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the
* underlying values.
* underlying values.
*/
*/
set
?(
val
:
unknown
):
void
;
set
?(
this
:
M
,
val
:
unknown
):
void
;
}
}
/**
/**
* Interface for Attributes provided for a column
* Interface for Attributes provided for a column
*/
*/
export
interface
ModelAttributes
{
export
interface
ModelAttributes
<
M
extends
Model
=
Model
>
{
/**
/**
* The description of a database column
* The description of a database column
*/
*/
[
name
:
string
]:
DataType
|
ModelAttributeColumnOptions
;
[
name
:
string
]:
DataType
|
ModelAttributeColumnOptions
<
M
>
;
}
}
/**
/**
...
@@ -1607,7 +1607,7 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
...
@@ -1607,7 +1607,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
<
M
extends
Model
=
Model
>
(
this
:
ModelCtor
<
M
>
,
attributes
:
ModelAttributes
,
options
:
InitOptions
<
M
>
):
void
;
public
static
init
<
M
extends
Model
=
Model
>
(
this
:
ModelCtor
<
M
>
,
attributes
:
ModelAttributes
<
M
>
,
options
:
InitOptions
<
M
>
):
void
;
/**
/**
* Remove attribute from model definition
* Remove attribute from model definition
...
...
types/test/model.ts
View file @
afb8cc3
...
@@ -50,7 +50,17 @@ MyModel.update({}, { where: { foo: 'bar' }, paranoid: false});
...
@@ -50,7 +50,17 @@ MyModel.update({}, { where: { foo: 'bar' }, paranoid: false});
const
sequelize
=
new
Sequelize
(
'mysql://user:user@localhost:3306/mydb'
);
const
sequelize
=
new
Sequelize
(
'mysql://user:user@localhost:3306/mydb'
);
MyModel
.
init
({},
{
MyModel
.
init
({
virtual
:
{
type
:
new
DataTypes
.
VIRTUAL
(
DataTypes
.
BOOLEAN
,
[
'num'
]),
get
()
{
return
this
.
getDataValue
(
'num'
)
+
2
;
},
set
(
value
:
number
)
{
this
.
setDataValue
(
'num'
,
value
-
2
);
}
}
},
{
indexes
:
[
indexes
:
[
{
{
fields
:
[
'foo'
],
fields
:
[
'foo'
],
...
@@ -92,4 +102,4 @@ UserModel.findCreateFind({
...
@@ -92,4 +102,4 @@ UserModel.findCreateFind({
* Test for primaryKeyAttributes.
* Test for primaryKeyAttributes.
*/
*/
class
TestModel
extends
Model
{};
class
TestModel
extends
Model
{};
TestModel
.
primaryKeyAttributes
;
TestModel
.
primaryKeyAttributes
;
\ No newline at end of file
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