Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export type Constructor<A> = new (...input: any[]) => A;
class BaseEntity {
id: number;
}
class Account extends BaseEntity {
name = "Jon"
}
function BaseService<EntityType extends BaseEntity>(Entity: Constructor<EntityType>) {
return class {
repository = Entity;
}
}
function ListService(Base: ReturnType<typeof BaseService>) {
return class extends Base {
list() {
return this.repository // has typeof BaseEntity - great! We do not know yet which service this List mixin will be applied to..
}
}
}
class AccountService extends BaseService(Account) {
test() {
this.repository // has typeof Account - great!
}
}
class ListableAccountService extends ListService(BaseService(Account)) {
test() {
this.repository // Has typeof BaseEntity - how can I get ListService to understand it should use type that was passed to BaseService????
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.