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 63ceb738
authored
Jun 25, 2021
by
JacobLey
Committed by
GitHub
Jun 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(typings): restrict update typings (#13216)
1 parent
143cc84c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
types/lib/model.d.ts
types/test/update.ts
types/lib/model.d.ts
View file @
63ceb73
...
@@ -2087,7 +2087,9 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
...
@@ -2087,7 +2087,9 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
*/
*/
public
static
update
<
M
extends
Model
>
(
public
static
update
<
M
extends
Model
>
(
this
:
ModelStatic
<
M
>
,
this
:
ModelStatic
<
M
>
,
values
:
Partial
<
M
[
'_attributes'
]
>
,
values
:
{
[
key
in
keyof
M
[
'_attributes'
]]?:
M
[
'_attributes'
][
key
]
|
Fn
|
Col
|
Literal
;
},
options
:
UpdateOptions
<
M
[
'_attributes'
]
>
options
:
UpdateOptions
<
M
[
'_attributes'
]
>
):
Promise
<
[
number
,
M
[]]
>
;
):
Promise
<
[
number
,
M
[]]
>
;
...
@@ -2744,8 +2746,13 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
...
@@ -2744,8 +2746,13 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
/**
/**
* This is the same as calling `set` and then calling `save`.
* This is the same as calling `set` and then calling `save`.
*/
*/
public
update
<
K
extends
keyof
this
>
(
key
:
K
,
value
:
this
[
K
],
options
?:
InstanceUpdateOptions
<
TModelAttributes
>
):
Promise
<
this
>
;
public
update
<
K
extends
keyof
TModelAttributes
>
(
key
:
K
,
value
:
TModelAttributes
[
K
]
|
Col
|
Fn
|
Literal
,
options
?:
InstanceUpdateOptions
<
TModelAttributes
>
):
Promise
<
this
>
;
public
update
(
keys
:
object
,
options
?:
InstanceUpdateOptions
<
TModelAttributes
>
):
Promise
<
this
>
;
public
update
(
keys
:
{
[
key
in
keyof
TModelAttributes
]?:
TModelAttributes
[
key
]
|
Fn
|
Col
|
Literal
;
},
options
?:
InstanceUpdateOptions
<
TModelAttributes
>
):
Promise
<
this
>
;
/**
/**
* Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will
* Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will
...
...
types/test/update.ts
View file @
63ceb73
import
{
Model
}
from
'sequelize'
;
import
{
Model
,
fn
,
col
,
literal
}
from
'sequelize'
;
import
{
User
}
from
'./models/User'
;
import
{
User
}
from
'./models/User'
;
class
TestModel
extends
Model
{
class
TestModel
extends
Model
{
...
@@ -11,8 +11,27 @@ TestModel.update({}, { where: {}, returning: ['foo'] });
...
@@ -11,8 +11,27 @@ TestModel.update({}, { where: {}, returning: ['foo'] });
User
.
update
({},
{
where
:
{}
});
User
.
update
({},
{
where
:
{}
});
User
.
update
({
id
:
123
,
username
:
fn
(
'FN'
),
firstName
:
col
(
'id'
),
lastName
:
literal
(
'Smith'
),
},
{
where
:
{}
});
User
.
update
({},
{
where
:
{},
returning
:
true
});
User
.
update
({},
{
where
:
{},
returning
:
true
});
User
.
update
({},
{
where
:
{},
returning
:
false
});
User
.
update
({},
{
where
:
{},
returning
:
false
});
User
.
update
({},
{
where
:
{},
returning
:
[
'username'
]
});
User
.
update
({},
{
where
:
{},
returning
:
[
'username'
]
});
// @ts-expect-error
User
.
build
().
update
({
id
:
123
,
username
:
fn
(
'FN'
),
firstName
:
col
(
'id'
),
lastName
:
literal
(
'Smith'
),
});
// @ts-expect-error invalid `returning`
User
.
update
({},
{
where
:
{},
returning
:
[
'foo'
]
});
User
.
update
({},
{
where
:
{},
returning
:
[
'foo'
]
});
// @ts-expect-error no `where`
User
.
update
({},
{});
// @ts-expect-error invalid attribute
User
.
update
({
foo
:
'<bar>'
},
{
where
:
{}
});
// @ts-expect-error invalid attribute
User
.
build
().
update
({
foo
:
'<bar>'
});
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