My user schema in typescript includes the following interface:
interface IUser{
name: string;
email: string;
password: string;
isAdmin: boolean;
}
Check out the user schema below:
const UserSchema = new Schema<IUser>(
{
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
validate: [validator.isEmail, "Please provide a valid email"],
},
password: {
type: String,
required: true,
minlength: 8,
},
isAdmin: {
type: Boolean,
required: true,
default: false,
},
},
{
timestamps: true,
}
);
const UserModel = model("User", UserSchema);
module.exports = UserModel;
I encountered an error with typescript stating that untyped function calls may not accept type arguments on the user schema while using express and mongoose with visual studio editor.