-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issuetypescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.7.2
Node.js version
22
MongoDB server version
6.11
Typescript version (if applicable)
5.7.2
Description
Before 8.7.2, only the type of the union was returned and that was fine. But now the type is returned as binary, but the union has no binaries in it.
It does not matter that the correct union value is not parsed here by mongoose, as this is done by zod.
This error seems to be related to this issue: #14974
Steps to Reproduce
import mongoose, { Model } from "mongoose";
type Attachment =
| {
type: "foo";
value?: undefined;
}
| {
type: "string";
value?: string;
};
const TestSchema = new mongoose.Schema<Attachment>({
type: { type: String, required: true },
value: { type: String },
});
export const AttachmentModel = mongoose.model<Attachment>("test", TestSchema);
const main = async () => {
const item = await AttachmentModel.findOne().lean();
if (!item) return;
doSomeThing(item);
};
const doSomeThing = (item: Attachment) => {
console.log(item);
};
Expected Behavior
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issuetypescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
