0

Given some interface:

interface IFoo {
    userService: IUserService
    authService: IAuthService
}

How do I retrieve IUserService and IAuthService via the following function:

function getInternalTypes<T>() {
    // Need to loop through T (somehow) and extract those types, for example to do something like:
    // IoCContainer.Resolve<K>(KString); // where K is the type IUserService and KString is the string "IUserService".
}

I know you can use keyof to get keys but not sure how I would go about getting the actual types for these keys (typeof? I don't know...)

AjLearning
  • 379
  • 5
  • 16
  • Are you asking [this](https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript)? What specifically are you expecting `getInternalTypes()` to output? – jcalz Apr 08 '20 at 02:20
  • What do you want to "extract those types" into? – CertainPerformance Apr 08 '20 at 02:20
  • @CertainPerformance Asumming I have access to a `type ValType` and a `string ValTypeString`, I'd like to `IoCContainer.resolve(ValTypeString)`. – AjLearning Apr 08 '20 at 02:48
  • @jcalz Thanks for suggesting that thread, I'll take a look. – AjLearning Apr 08 '20 at 02:49
  • @jcalz Using that link, I'd say I might be able to get a union of all value types, but I still don't know how I'd extract these one at a time. Further to my comment above, inside my `getInternalTypes` function, I'd like to be able to go `IoCContainer.resolve(KString)` where `K` is the type `IUserService` (for example) and (if possible, but not necessary), `KString` is the string `"IUserService"`. – AjLearning Apr 08 '20 at 03:19
  • Have edited the question to reflect this. – AjLearning Apr 08 '20 at 03:22

0 Answers0