2021年1月18日星期一

Typescript extending a generic typed class

This is the class that I want to extend

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[]>;  }  

as you can see, it has T that extends to an IEntity

Currently, here's my code

import { BaseFirestoreRepository, IEntity } from 'fireorm'    interface ICustomRepository<T extends IEntity> {    where(filter: any): BaseFirestoreRepository<T>  }    BaseFirestoreRepository.prototype.where = function () {}  

I am not sure it is correct because I didnt pass the type when I do the prototype and also the where shows an error the Property 'where' does not exist on type 'BaseFirestoreRepository<any>'

https://stackoverflow.com/questions/65784962/typescript-extending-a-generic-typed-class January 19, 2021 at 11:04AM

没有评论:

发表评论