diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index cb117779cd..9ffda92873 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -2190,6 +2190,15 @@ declare namespace sequelize { } + interface EmptyResultError extends BaseError { + + /** + * Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details) + */ + new (parent: Error): EmptyResultError; + + } + /** * Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors * are exposed on the sequelize object and the sequelize constructor. All sequelize errors inherit from the @@ -2211,6 +2220,7 @@ declare namespace sequelize { HostNotReachableError: HostNotReachableError; InvalidConnectionError: InvalidConnectionError; ConnectionTimedOutError: ConnectionTimedOutError; + EmptyResultError: EmptyResultError; } // @@ -3275,6 +3285,11 @@ declare namespace sequelize { * Prevents a subquery on the main table when using include */ subQuery?: boolean; + + /** + * Throw EmptyResultError if a record is not found + */ + rejectOnEmpty?: boolean; } type AnyFindOptions = FindOptions; diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index fcb273f5e2..9000dd92b0 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -629,6 +629,7 @@ new s.HostNotFoundError( new Error( 'original connection error message' ) ); new s.HostNotReachableError( new Error( 'original connection error message' ) ); new s.InvalidConnectionError( new Error( 'original connection error message' ) ); new s.ConnectionTimedOutError( new Error( 'original connection error message' ) ); +new s.EmptyResultError(); const uniqueConstraintError: Sequelize.ValidationError = new s.UniqueConstraintError({}); @@ -914,6 +915,7 @@ User.findAll( { attributes: [s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER' User.findAll( { attributes: [[s.cast(s.fn('count', Sequelize.col('*')), 'INTEGER'), 'count']] }); User.findAll( { where : s.fn('count', [0, 10]) } ); User.findAll( { subQuery: false, include : [User], order : [[User, User, 'numYears', 'c']] } ); +User.findAll( { rejectOnEmpty: true }); User.findById( 'a string' );