Created
June 17, 2020 11:04
-
-
Save PatrickGeyer/35c15a4d58f24b540386c9a6aa70642c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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