From 398ff1e7e7b9532ef7cce65effe5f78ec2bb5220 Mon Sep 17 00:00:00 2001 From: Kapunahele Wong Date: Sat, 19 Oct 2019 08:13:30 -0400 Subject: [PATCH] docs: add ModuleWithProviders deprecation (#33266) PR Close #33266 --- aio/content/guide/deprecations.md | 48 ++++++++++++++++++++++++- packages/core/src/metadata/ng_module.ts | 3 ++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/aio/content/guide/deprecations.md b/aio/content/guide/deprecations.md index 6e4693b6b2..5e4decfa10 100644 --- a/aio/content/guide/deprecations.md +++ b/aio/content/guide/deprecations.md @@ -38,6 +38,7 @@ v9 - v12 | `@angular/common` | [`ReflectiveInjector`](#reflectiveinjector) | v9 | | `@angular/core` | [`CollectionChangeRecord`](#core) | v9 | | `@angular/core` | [`DefaultIterableDiffer`](#core) | v9 | +| `@angular/core` | [`ModuleWithProviders` without a generic](#moduleWithProviders) | v10 | | `@angular/core` | [`ReflectiveKey`](#core) | v9 | | `@angular/core` | [`RenderComponentType`](#core) | v9 | | `@angular/core` | [`ViewEncapsulation.Native`](#core) | v9 | @@ -56,7 +57,6 @@ v9 - v12 - ## Deprecated APIs This section contains a complete list all of the currently-deprecated APIs, with details to help you plan your migration to a replacement. @@ -88,6 +88,8 @@ Tip: In the [API reference section](api) of this doc site, deprecated APIs are i | [`ANALYZE_FOR_ENTRY_COMPONENTS`](api/core/ANALYZE_FOR_ENTRY_COMPONENTS) | none | v9 | See [`ANALYZE_FOR_ENTRY_COMPONENTS`](#entryComponents) | + + {@a testing} ### @angular/core/testing @@ -334,6 +336,50 @@ This includes both packages: `@angular/platform-webworker` and ### `entryComponents` and `ANALYZE_FOR_ENTRY_COMPONENTS` no longer required Previously, the `entryComponents` array in the `NgModule` definition was used to tell the compiler which components would be created and inserted dynamically. With Ivy, this isn't a requirement anymore and the `entryComponents` array can be removed from existing module declarations. The same applies to the `ANALYZE_FOR_ENTRY_COMPONENTS` injection token. +{@a moduleWithProviders} +### `ModuleWithProviders` type without a generic + +Some Angular libraries, such as `@angular/router` and `@ngrx/store`, implement APIs that return a type called `ModuleWithProviders` (typically via a method named `forRoot()`). +This type represents an `NgModule` along with additional providers. +Angular version 9 deprecates use of `ModuleWithProviders` without an explicitly generic type, where the generic type refers to the type of the `NgModule`. +In a future version of Angular, the generic will no longer be optional. + + +If you're using the CLI, `ng update` should [migrate your code automatically](guide/migration-module-with-providers). +If you're not using the CLI, you can add any missing generic types to your application manually. +For example: + +**Before** +```ts +@NgModule({...}) +export class MyModule { + static forRoot(config: SomeConfig): ModuleWithProviders { + return { + ngModule: SomeModule, + providers: [ + {provide: SomeConfig, useValue: config} + ] + }; + } +} +``` + +**After** + +```ts +@NgModule({...}) +export class MyModule { + static forRoot(config: SomeConfig): ModuleWithProviders { + return { + ngModule: SomeModule, + providers: [ + {provide: SomeConfig, useValue: config } + ] + }; + } +} +``` + ## Angular version 9 schematics diff --git a/packages/core/src/metadata/ng_module.ts b/packages/core/src/metadata/ng_module.ts index 5c9f85991f..a7c0af052d 100644 --- a/packages/core/src/metadata/ng_module.ts +++ b/packages/core/src/metadata/ng_module.ts @@ -86,6 +86,9 @@ export interface NgModuleDef { * @param T the module type. In Ivy applications, this must be explicitly * provided. * + * Note that using ModuleWithProviders without a generic type is deprecated. + * The generic will become required in a future version of Angular. + * * @publicApi */ export interface ModuleWithProviders<