ITADN

`Model.validate()` types are wrong

#16338Closedtomkel 创建于 2026-06-22
T
tomkelcommented
### Prerequisites - [x] I have written a descriptive issue title - [x] I have searched existing issues to ensure the bug has not already been reported ### 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` https://github.com/Automattic/mongoose/blob/03bedeaf57b3154cc89178fbb547cd16a951ccc0/types/models.d.ts#L687-L691 It says return type is `void`. But that's not true because `validate` calls `castObj` and returns it. https://github.com/Automattic/mongoose/blob/7fee4b58ce881716ad91c16a8e82c78341742274/lib/model.js#L4316 ### Steps to Reproduce ```ts conts validated = await MyModel.validate({ a: 'string' }) validated.a // ts(2339): Property 'a' does not exist on type 'void'. ``` ### Expected Behavior _No response_
关闭于 2026-06-23 0 条评论