I created an abstract class called CustomRepository:
import { Repository as R, BaseEntity } from 'typeorm';
import Repository from '../interfaces/Repository';
abstract class CustomRepository<T extends BaseEntity> implements Repository<T> {
constructor(protected repository: R<T>) {}
create = async (obj: T): Promise<T> => this.repository.save(obj);
getAll = async (): Promise<T[]> => this.repository.find();
getById = async (_id: string): Promise<T | null> =>
this.repository.findOneBy({ id: _id });
}
That implements this interface:
export interface Repository<T> {
create(obj: T): Promise<T>;
getAll(): Promise<T[]>;
getById(id: string): Promise<T | null>;
}
I'm trying to implement a "find by id" in this class using TypeORM "findOneBy" method, but it warns me with:
Argument of type '{ id: string; }' is not assignable to parameter of type 'FindOptionsWhere<T> | FindOptionsWhere<T>[]'.
Object literal may only specify known properties, and 'id' does not exist in type 'FindOptionsWhere<T> | FindOptionsWhere<T>[]'.ts(2345)