Cannot find namespace 'mongoose' when creating a static function in a model in TypescriptError in finding namespace Mongoose
The code snippet shown below gives error highlighting the Model keyword
const mongoose = require('mongoose');
interface UserAttribs{
email:String;
password:String;
}
interface UserModel extends mongoose.Model{
build(attribs: UserAttribs):any;
}
const userSchema = mongoose.Schema({
email:{
type:String,
required: true
},
password:{
type:String,
required: true
}
});
userSchema.statics.build = (attribs:UserAttribs)=>{
return new User(attribs);
}
const User = mongoose.model('User',userSchema);
export { User };
When we hover on 'Model' the error states 'cannot find namespace mongoose' Please help