Skip to content

Commit

Permalink
Added no-argument overload for Model.previous (DefinitelyTyped#29385)
Browse files Browse the repository at this point in the history
* Added no-argument overload for Model.previous

`Model.previous()` in Sequelize called with no arguments returns an object containing the previous keys and values for properties that have changed. This pull request adds this overload to the Model.d.ts type definition file along with a comment documenting it.

* Added test for Model.previous w no arg
  • Loading branch information
devuxer authored and weswigham committed Oct 3, 2018
1 parent 35b5eba commit 430376c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion types/sequelize/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2890,9 +2890,12 @@ declare namespace sequelize {
changed(): boolean | string[];

/**
* Returns the previous value for key from `_previousDataValues`.
* If previous is called with a string, it will return the previous value for the key from `_previousDataValues`.
*
* If previous is called without an argument, it will return an object containing the previous keys and values that have changed.
*/
previous(key: keyof TAttributes): any;
previous(): object;

/**
* Validate this instance, and if the validation passes, persist it to the database.
Expand Down
1 change: 1 addition & 0 deletions types/sequelize/sequelize-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ user.changed( 'name' );
user.changed();

user.previous( 'name' );
user.previous();

user.save().then( ( p ) => p );
user.save( { fields : ['a'] } ).then( ( p ) => p );
Expand Down

0 comments on commit 430376c

Please sign in to comment.