I am interested in extending the following class:
import 'reflect-metadata';
import { IRepository, IFireOrmQueryLine, IOrderByParams, IEntity } from './types';
import { AbstractFirestoreRepository } from './AbstractFirestoreRepository';
import { TransactionRepository } from './Transaction/BaseFirestoreTransactionRepository';
export declare class BaseFirestoreRepository<T extends IEntity> extends AbstractFirestoreRepository<T> implements IRepository<T> {
private readonly firestoreColRef;
constructor(colName: string, collectionPath?: string);
findById(id: string): Promise<T>;
create(item: T): Promise<T>;
update(item: T): Promise<T>;
delete(id: string): Promise<void>;
runTransaction<R>(executor: (tran: TransactionRepository<T>) => Promise<R>): Promise<R>;
createBatch(): import("./Batch/FirestoreBatchSingleRepository").FirestoreBatchSingleRepository<T>;
execute(queries: Array<IFireOrmQueryLine>, limitVal?: number, orderByObj?: IOrderByParams, single?: boolean): Promise<T[]>;
}
It is noted that it includes T
which extends an IEntity.
I currently have this code snippet:
import { BaseFirestoreRepository, IEntity } from 'fireorm'
interface ICustomRepository<T extends IEntity> {
where(filter: any): BaseFirestoreRepository<T>
}
BaseFirestoreRepository.prototype.where = function () {}
I am uncertain if this implementation is correct because I did not provide the type when using prototype
, and the where
function displays an error saying
Property 'where' does not exist on type 'BaseFirestoreRepository<any>'
.
My ultimate goal is to implement a function similar to C# extension methods like this:
public static IQueryable<T> OrderByPropertyName<T>(this IQueryable<T> query, string attribute, string direction) {
// my logic here
}
This way, I can directly add methods to a class similar to how prototype functions work.