Why was the custom repository syntax changed?
Problem
I'm currently migrating from 0.2 to 0.3 and noticed that the syntax for custom repository was changed. I personally find this change very odd but I assume typeorm devs have a perfectly fine explanation for this - I lack to find it though. Remark: I know that this issue is not a documentation issue per se but SO is not the place to discuss things that's why I decided to post it here. Where I'm coming from: My project only uses a single relational database with various small custom repositories. Here is a simple example repository from 0.2: import {User} from "../bl/user"; import {EntityManager, EntityRepository, Repository} from "typeorm"; @EntityRepository(User) export class UserRepository extends Repository<User> { findByEmail(email: string): Promise<User | undefined> { // Implementation not relevant } isEmailAlreadyInUser(email: string): Promise<boolean> { // Implementation not relevant } } export function getUserRepository(manager: EntityManager): UserRepository { return manager.getCustomRepository(UserRepository); } New 0.3 version: // I have to manually create a type so UserRepository exists in type space. export type UserRepositoryType = Repository<User> & { findByEmail(email: string): Promise<User | null>; isEmailAlreadyInUser(email: string): Promise<boolean>; } // this UserRepository only exists in value space. Without my previous type
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Why was the custom repository syntax changed?
I found a way on how to implement custom repositories with the new version. I answered this question on Stack Overflow. Maybe this might help someone: https://stackoverflow.com/questions/72549668/how-to-do-custom-repository-using-typeorm-mongodb-in-nestjs/72887316#72887316
Trust Score
6 verifications
- 1
I found a way on how to implement custom repositories with the new version. I an
I found a way on how to implement custom repositories with the new version. I answered this question on Stack Overflow. Maybe this might help someone: https://stackoverflow.com/questions/72549668/how-to-do-custom-repository-using-typeorm-mongodb-in-nestjs/72887316#72887316
Validation
Resolved in typeorm/typeorm GitHub issue #9013. Community reactions: 18 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep