Prerequisites
Mongoose version
9.7.1
Node.js version
26.3.1
MongoDB server version
8.3.4
Typescript version (if applicable)
6.0.3
Description
Here are the current types for Model.validate
|
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */ |
|
validate(): Promise<void>; |
|
validate(obj: any): Promise<void>; |
|
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<void>; |
|
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<void>; |
It says return type is void. But that's not true because validate calls castObj and returns it.
|
obj = this.castObject(obj); |
Steps to Reproduce
conts validated = await MyModel.validate({ a: 'string' })
validated.a // ts(2339): Property 'a' does not exist on type 'void'.
Expected Behavior
No response
Prerequisites
Mongoose version
9.7.1
Node.js version
26.3.1
MongoDB server version
8.3.4
Typescript version (if applicable)
6.0.3
Description
Here are the current types for
Model.validatemongoose/types/models.d.ts
Lines 687 to 691 in 03bedea
It says return type is
void. But that's not true becausevalidatecallscastObjand returns it.mongoose/lib/model.js
Line 4316 in 7fee4b5
Steps to Reproduce
Expected Behavior
No response