I came across this helpful solution here
After studying it, I saw potential for improvement to make it more versatile. That's when I developed a new, even more universal generic type:
export type extractGeneric<Type, Parent> = Type extends Parent<infer Entity> ? Entity : never
But I encountered an issue where TypeScript is flagging an error stating Type 'Parent' is not generic
Type 'Parent' is not generic.ts(2315)
To resolve this, the typical solution involves hardcoding it with Repository
like so:
import { Repository } from "typeorm"
export type extractGeneric<Type> = Type extends Repository<infer Entity> ? Entity : never