mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Invalid type for Buffer

Open giqnt opened this issue 1 year ago • 2 comments

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)

giqnt avatar Sep 21 '24 05:09 giqnt

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?

vkarpov15 avatar Sep 23 '24 20:09 vkarpov15

Oh sorry i forgot about this issue, it turned out Buffer field will be Binary for leaned document.

giqnt avatar Sep 24 '24 10:09 giqnt