-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
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
9.0.1
Node.js version
x
MongoDB server version
x
Typescript version (if applicable)
5.9.3
Description
Works in 8x, and 9.0.0.
Fairly sure this is related to #15824
Given this setup:
enum MyEnum {
Hello = 0,
GoodBye,
}
myEnumProperty: { type: Number, enum: MyEnum, required: true, default: 0 },Getting an error like this:
Cast to Number failed for value "Hello" (type string) at path "myEnumProperty"
Steps to Reproduce
Schema with something like this:
import mongoose, { Schema } from 'mongoose';
enum MyEnum {
Hello = 0,
GoodBye,
}
const schema = new Schema<User>({
name: { type: String, required: true },
email: { type: String, required: true },
myEnumProperty: { type: Number, enum: MyEnum, required: true, default: 0 },
avatar: String,
});
interface User {
name: string;
email: string;
avatar?: string;
}
const UserModel = mongoose.model<User>('User', schema);
const doc = new UserModel({ name: 'test', email: 'test', myEnumProperty: MyEnum.GoodBye });Expected Behavior
No errors
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels