diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 44570b3ff5..9a89b8928c 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -977,7 +977,9 @@ declare module "mongoose" { validate?: RegExp | [RegExp, string] | SchemaTypeOpts.ValidateFn | [SchemaTypeOpts.ValidateFn, string] | SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.AsyncValidateOpts | - (SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.AsyncValidateOpts)[]; + SchemaTypeOpts.AsyncPromiseValidationFn | SchemaTypeOpts.AsyncPromiseValidationOpts | + (SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.AsyncValidateOpts | + SchemaTypeOpts.AsyncPromiseValidationFn | SchemaTypeOpts.AsyncPromiseValidationOpts)[]; /** Declares an unique index. */ unique?: boolean | any; @@ -1060,6 +1062,14 @@ declare module "mongoose" { validator: AsyncValidateFn; } + interface AsyncPromiseValidationFn { + (value: T): Promise; + } + + interface AsyncPromiseValidationOpts extends ValidateOptsBase { + validator: AsyncPromiseValidationFn; + } + interface EnumOpts { values?: T[]; message?: string; diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index dc7c4fb6c6..ca06ec8655 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -524,7 +524,15 @@ new mongoose.Schema({ setImmediate(done, true); } } - } + }, + promiseValidated: { + type: Number, + validate: { + validator: async (val: number) => { + return val === 2; + } + } + }, }); new mongoose.Schema({ name: { type: String, validate: [ { validator: () => {return true}, msg: 'uh oh' },