不要怂,就是干,撸起袖子干!

Commit 63ceb738 by JacobLey Committed by GitHub

fix(typings): restrict update typings (#13216)

1 parent 143cc84c
Showing with 31 additions and 5 deletions
......@@ -2087,7 +2087,9 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
*/
public static update<M extends Model>(
this: ModelStatic<M>,
values: Partial<M['_attributes']>,
values: {
[key in keyof M['_attributes']]?: M['_attributes'][key] | Fn | Col | Literal;
},
options: UpdateOptions<M['_attributes']>
): Promise<[number, M[]]>;
......@@ -2744,8 +2746,13 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
/**
* 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(keys: object, 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: {
[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
......
import { Model } from 'sequelize';
import { Model, fn, col, literal } from 'sequelize';
import { User } from './models/User';
class TestModel extends Model {
......@@ -11,8 +11,27 @@ TestModel.update({}, { where: {}, returning: ['foo'] });
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: false });
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'] });
// @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>' });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!