I'm using ORM library as typeorm and studying object-oriented with typescript.
// IUserRepository.ts
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
export interface IUserRepository {
update(id: number, payload: QueryDeepPartialEntity<User>): Promise<User>;
}
The payload of an interface depends on the implementation, and I do not think that it is appropriate for the reason to use the interface because if change the code to another implementation, the interface must also be modified.
But update of typeorm is required QueryDeepPartialEntity<any>
// user.repository.ts
export class UserRepository implements IUserRepository {
// ...
async update(
id: number,
payload: QueryDeepPartialEntity<User>
): Promise<User> {
const repository = await this.database.getRepository(User);
const updatedUser = await repository
.update(id, payload)
.then(async () => await repository.findOne({ where: { id } }));
return updatedUser;
}
}
how can i resolve it?