docs: add ModuleWithProviders deprecation (#33266)

PR Close #33266
This commit is contained in:
Kapunahele Wong 2019-10-19 08:13:30 -04:00 committed by Kara Erickson
parent b3d6d500be
commit 398ff1e7e7
2 changed files with 50 additions and 1 deletions

View File

@ -38,6 +38,7 @@ v9 - v12
| `@angular/common` | [`ReflectiveInjector`](#reflectiveinjector) | <!--v8--> v9 |
| `@angular/core` | [`CollectionChangeRecord`](#core) | <!--v7--> v9 |
| `@angular/core` | [`DefaultIterableDiffer`](#core) | <!--v7--> v9 |
| `@angular/core` | [`ModuleWithProviders` without a generic](#moduleWithProviders) | v10 |
| `@angular/core` | [`ReflectiveKey`](#core) | <!--v8--> v9 |
| `@angular/core` | [`RenderComponentType`](#core) | <!--v7--> 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<SomeModule> {
return {
ngModule: SomeModule,
providers: [
{provide: SomeConfig, useValue: config }
]
};
}
}
```
## Angular version 9 schematics

View File

@ -86,6 +86,9 @@ export interface NgModuleDef<T> {
* @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<