An outer value of 'this' is shadowed by this container with Mongoose Schema Typescript

Viewed 3808

I have the following for a schema validator for MongoDB:{

UserSchema.path('email').validate(async function (email: string) {
  const count = await User.count({ email, _id: { $ne: this._id } })
  return !count
}, 'Email already exists')

I'm getting the following error:

'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)
User.ts(171, 35): An outer value of 'this' is shadowed by this container.

This is defined in my User.ts file. Everything works exactly as expected but this Typescript error is blocking CI from continuing. Is there anyway to get around this (no pun intended).

1 Answers
Related