-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(common): Add generic to InjectionToken type #11555
Merged
kamilmysliwiec
merged 33 commits into
nestjs:10.0.0
from
MaurerKrisztian:InjectionToken-generic
Apr 25, 2023
Merged
refactor(common): Add generic to InjectionToken type #11555
kamilmysliwiec
merged 33 commits into
nestjs:10.0.0
from
MaurerKrisztian:InjectionToken-generic
Apr 25, 2023
Conversation
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
Bumps [mongoose](https://github.com/Automattic/mongoose) from 7.0.3 to 7.0.4. - [Release notes](https://github.com/Automattic/mongoose/releases) - [Changelog](https://github.com/Automattic/mongoose/blob/master/CHANGELOG.md) - [Commits](Automattic/mongoose@7.0.3...7.0.4) --- updated-dependencies: - dependency-name: mongoose dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@types/sinon](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/sinon) from 10.0.13 to 10.0.14. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/sinon) --- updated-dependencies: - dependency-name: "@types/sinon" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
chore(deps): update dependency tsconfig-paths to v4.2.0
fix(deps): update dependency @nestjs/swagger to v6.3.0
fix(deps): update dependency @nestjs/schedule to v2.2.1
fix(deps): update dependency @grpc/grpc-js to v1.8.14
fix(deps): update dependency @fastify/static to v6.10.1
fix(deps): update dependency @nestjs/graphql to v10.2.1
…ypes/sinon-10.0.14 chore(deps-dev): bump @types/sinon from 10.0.13 to 10.0.14
…ongoose-7.0.4 chore(deps-dev): bump mongoose from 7.0.3 to 7.0.4
fix(deps): update dependency mongoose to v6.10.5
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.15.11 to 18.15.12. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
…ypes/node-18.15.12 chore(deps-dev): bump @types/node from 18.15.11 to 18.15.12
Bumps [@apollo/server](https://github.com/apollographql/apollo-server/tree/HEAD/packages/server) from 4.6.0 to 4.7.0. - [Release notes](https://github.com/apollographql/apollo-server/releases) - [Changelog](https://github.com/apollographql/apollo-server/blob/main/packages/server/CHANGELOG.md) - [Commits](https://github.com/apollographql/apollo-server/commits/@apollo/server@4.7.0/packages/server) --- updated-dependencies: - dependency-name: "@apollo/server" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [sinon](https://github.com/sinonjs/sinon) from 15.0.3 to 15.0.4. - [Release notes](https://github.com/sinonjs/sinon/releases) - [Changelog](https://github.com/sinonjs/sinon/blob/main/docs/changelog.md) - [Commits](sinonjs/sinon@v15.0.3...v15.0.4) --- updated-dependencies: - dependency-name: sinon dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
…inon-15.0.4 chore(deps-dev): bump sinon from 15.0.3 to 15.0.4
…pollo/server-4.7.0 chore(deps-dev): bump @apollo/server from 4.6.0 to 4.7.0
chore: update repo references in package.json files
Bumps [cache-manager](https://github.com/node-cache-manager/node-cache-manager) from 5.2.0 to 5.2.1. - [Release notes](https://github.com/node-cache-manager/node-cache-manager/releases) - [Changelog](https://github.com/node-cache-manager/node-cache-manager/blob/master/CHANGELOG.md) - [Commits](jaredwray/cacheable@5.2.0...5.2.1) --- updated-dependencies: - dependency-name: cache-manager dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [prettier](https://github.com/prettier/prettier) from 2.8.7 to 2.8.8. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](prettier/prettier@2.8.7...2.8.8) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.15.12 to 18.16.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
…ache-manager-5.2.1 chore(deps-dev): bump cache-manager from 5.2.0 to 5.2.1
…ypes/node-18.16.0 chore(deps-dev): bump @types/node from 18.15.12 to 18.16.0
…rettier-2.8.8 chore(deps-dev): bump prettier from 2.8.7 to 2.8.8
Pull Request Test Coverage Report for Build 5aed9202-f4a6-47ab-a0e2-d7d85f50e81b
💛 - Coveralls |
micalevisk
approved these changes
Apr 24, 2023
Could you show how the generic will help here? |
Sure! Here's a simplified use case for the generic. export interface IProvider {
provide(context: string): unknown;
} @Module({})
export class ExampleModule implements NestModule {
static forRootAsync(options: { customProvider: InjectionToken<IProvider> }): DynamicModule {
return {
module: ExampleModule,
imports: [],
providers: [
{
provide: 'Key', // this is used in this module to do some things..
useFactory: (provider: IProvider, context: string) => {
// the module will provide the context..
const result = provider.provide(context);
// ...
return result;
},
inject: [options.customProvider, 'context'],
},
{
provide: 'context',
useValue: 'world!',
},
],
exports: [],
};
}
configure(consumer: MiddlewareConsumer): void {}
} the module user perspective: export class ExampleProvider implements IProvider {
// the context is provided by the module
provide(context: string): unknown {
return `Hello ${context}`;
}
} App module imports: ExampleModule.forRootAsync({ customProvider: ExampleProvider }),
ExampleModule.forRootAsync({ customProvider: 'ProviderKey' }), This customProvider must implement the IProvider interface because the module uses it. |
lgtm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The InjectionToken type permits the use of any string, Type, Abstract, etc. However, it is not possible to indicate an InjectionToken Type that implements a specific interface.
Issue Number: N/A
What is the new behavior?
The new code now incorporates a generic type parameter T into the InjectionToken. This addition is particularly useful for creating dynamic modules that require an InjectionToken provider token.
Without this generic type, the code would be less robust in terms of type safety.
Fortunately, this change maintains compatibility with the previous behavior.
Does this PR introduce a breaking change?
Other information