mongoose
mongoose copied to clipboard
Invalid type for Buffer
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
8.6.3
Node.js version
doesn't matter
MongoDB server version
doesn't matter
Typescript version (if applicable)
5.6.2
Description
InferSchemaType returns Buffer instead of Binary(from BSON) for Buffer field
Steps to Reproduce
const exampleSchema = new Schema({
image: { type: Buffer },
});
export type Example = InferSchemaType<typeof exampleSchema>;
// type Example = {
// image?: Buffer | null | undefined;
// }
Expected Behavior
type Example is:
type Example = {
image?: Binary | null | undefined;
}
(Binary from BSON)
That's correct in the sense that image will typically be a Buffer when you access that property. What is your use case for image being a Binary?
Oh sorry i forgot about this issue, it turned out Buffer field will be Binary for leaned document.