From 430376c0b38b4e8818fbf19bc4c517fb522f273c Mon Sep 17 00:00:00 2001 From: devuxer Date: Wed, 3 Oct 2018 11:49:11 -0700 Subject: [PATCH] Added no-argument overload for Model.previous (#29385) * 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 --- types/sequelize/index.d.ts | 5 ++++- types/sequelize/sequelize-tests.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 8c6622c1ab..0625a6406a 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -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. diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index 702821ae25..0592a36df4 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -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 );