typescript mongoose - this proprety is undefined

Viewed 9

In mongoose, I am writing a statics function to see if the email is already registered. I am facing an issue with 'this'. It tells me that it's value is undefined. Does anyone knows how to write this with typescript?

UserSchema.statics.signup = async (email: string, password: string) => {
    const exists = await this.findOne({email})
    if(exists) {
        throw Error('This email is already in use')
    }
}
0 Answers
Related