So I am using Typescript and ES6 classes, I came across an issue that somewhat confuses me, I have a class like so
export class RemoveUser {
constructor(private usersDb: IUserDb) {
this.remove = this.remove.bind(this)
}
async remove({id}: {id: ID}) {
if(!id) {
throw new RequiredParameterError('Id')
}
const userToDelete = await this.usersDb.findById({ id })
if(!userToDelete) {
throw new InvalidPropertyError('User does not exist.')
}
const {_id} = userToDelete
async function hardDelete(user: IUser) {
await this.usersDb.remove({id: _id}) // this line right here.
return {
deletedCount: 1,
message: 'User deleted.'
}
}
...
}
In the code snippet where I mark this line right here
, I get a highlight that 'this' implicitly has type 'any' because it does not have a type annotation. An outer value of 'this' is shadowed by this container.
What does it mean? One way I could solve the issue is to import usersDb
directly into the file, but I don't aim to do that as I am trying to achieve decoupling the application and using repositories. Thank you.