diff --git a/src/repository/Repository.ts b/src/repository/Repository.ts index 1108e97fa8..587cb419dd 100644 --- a/src/repository/Repository.ts +++ b/src/repository/Repository.ts @@ -634,13 +634,13 @@ export class Repository { // ...this, // ...custom // }; - const thisRepo: any = this.constructor + const thisRepo = this.constructor as new (...args: any[]) => typeof this const { target, manager, queryRunner } = this - const cls = new (class extends thisRepo { - constructor() { - super(target, manager, queryRunner) - } - })() + const cls = new (class extends thisRepo {})( + target, + manager, + queryRunner, + ) Object.assign(cls, custom) return cls as any } diff --git a/src/repository/TreeRepository.ts b/src/repository/TreeRepository.ts index 9a3bafdcf3..b105d61797 100644 --- a/src/repository/TreeRepository.ts +++ b/src/repository/TreeRepository.ts @@ -413,13 +413,13 @@ export class TreeRepository extends Repository { custom: CustomRepository & ThisType & CustomRepository>, ): TreeRepository & CustomRepository { - const thisRepo: any = this.constructor + const thisRepo = this.constructor as new (...args: any[]) => typeof this const { target, manager, queryRunner } = this - const cls = new (class extends thisRepo { - constructor() { - super(target, manager, queryRunner) - } - })() + const cls = new (class extends thisRepo {})( + target, + manager, + queryRunner, + ) Object.assign(cls, custom) return cls as any } diff --git a/test/functional/custom-repository/custom-repository.test.ts b/test/functional/custom-repository/custom-repository.test.ts index 45fc212078..ace137ebb3 100644 --- a/test/functional/custom-repository/custom-repository.test.ts +++ b/test/functional/custom-repository/custom-repository.test.ts @@ -43,7 +43,9 @@ describe("custom repository", () => { await transactionalManager.withRepository( CustomRepository, ) - await CustomRepository.save({ name: "Natures Prophet" }) + await transactionalCustomRepository.save({ + name: "Natures Prophet", + }) const user = await transactionalCustomRepository.findOneByName( "Natures Prophet",