Skip to content

Instantly share code, notes, and snippets.

@PatrickGeyer
Created June 17, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickGeyer/35c15a4d58f24b540386c9a6aa70642c to your computer and use it in GitHub Desktop.
Save PatrickGeyer/35c15a4d58f24b540386c9a6aa70642c to your computer and use it in GitHub Desktop.
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