Typescript utility type to extract the target (generic) type of an injection token#2135
Typescript utility type to extract the target (generic) type of an injection token#2135gthau wants to merge 1 commit intographql-hive:masterfrom
Conversation
…e of an injection token.
This allows to write injected dependencies like:
- given the following injection token:
```ts
const MyToken = new InjectionToken<Promise<Array<string | number>>>('my-token');
```
you can write:
```ts
type MyTokenTargetType = InjectionTokenTargetType<typeof MyToken>;
class MyClass {
constructor(@Inject(MyToken) someField: MyTokenTargetType) {}
}
```
instead of:
```ts
const MyToken = new InjectionToken<Promise<Array<string | number>>>('my-token');
class MyClass {
constructor(@Inject(MyToken) someField: Promise<Array<string | number>>) {}
}
```
|
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/theguild/graphql-modules/ArWnHZfMJEBn2P6THS571VhodATo |
Created a typescript utility type to extract the target (generic) type of an injection token.
This allows to write injected dependencies like:
you can write:
instead of:
🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.
Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
Screenshots/Sandbox (if appropriate/relevant):
Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Environment:
@graphql-modules/...:Checklist:
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...