Mongoose recently updated to accept a model generic it works well with a string type but not with a boolean type. 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); // Typescript complains here.
Example is posted here https://github.com/Automattic/mongoose/pull/9761
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…