Recently, there was an update in Mongoose that allows it to accept a model generic. While it works perfectly fine with a string type, it seems to have trouble with a boolean type, giving the error message
Type 'boolean' is not assignable to type 'SchemaDefinitionProperty<undefined>'
.
interface User {
firstName: string;
lastName: string;
email: string;
password: string;
isVerified?: boolean;
}
const UserSchemaDefinition: SchemaDefinition<User> = {
firstName: {
type: String,
trim: true,
required: true,
},
lastName: {
type: String,
trim: true,
required: true,
},
email: {
type: String,
required: true,
},
password: {
type: String,
required: true,
private: true,
},
isVerified: {
type: Boolean,
default: false,
},
};
const UserSchema = new mongoose.Schema(UserSchemaDefinition); // Issue arises here.
An example related to this issue can be found at this link.