Tengo lo siguiente para un validador de esquema para MongoDB:{
UserSchema.path('email').validate(async function (email: string) { const count = await User.count({ email, _id: { $ne: this._id } }) return !count }, 'Email already exists')Recibo el siguiente 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. Esto se define en mi archivo User.ts Todo funciona exactamente como se esperaba, pero este error de mecanografiado impide que CI continúe. ¿Hay alguna forma de evitar esto (sin juego de palabras)?
Tratar:
UserSchema.path('email').validate(async function (this:any, email: string) { const count = await User.count({ email, _id: { $ne: this._id } }) return !count }, 'Email already exists')Puede usar su tipo en lugar de "cualquiera".
Y el enlace al documento: https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters