Skip to content

Commit cbbad1b

Browse files
alexeaglebenlesh
authored andcommitted
refactor(ivy): pre-factor: set explicit type parameters for ModuleWithProviders (angular#25970)
Ivy depends on having the generic type token later when reading the ModuleWithProviders from a .d.ts file. PR Close angular#25970
1 parent 96ee898 commit cbbad1b

File tree

9 files changed

+21
-20
lines changed

9 files changed

+21
-20
lines changed

packages/common/http/src/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class HttpClientXsrfModule {
100100
/**
101101
* Disable the default XSRF protection.
102102
*/
103-
static disable(): ModuleWithProviders {
103+
static disable(): ModuleWithProviders<HttpClientXsrfModule> {
104104
return {
105105
ngModule: HttpClientXsrfModule,
106106
providers: [
@@ -120,7 +120,7 @@ export class HttpClientXsrfModule {
120120
static withOptions(options: {
121121
cookieName?: string,
122122
headerName?: string,
123-
} = {}): ModuleWithProviders {
123+
} = {}): ModuleWithProviders<HttpClientXsrfModule> {
124124
return {
125125
ngModule: HttpClientXsrfModule,
126126
providers: [

packages/core/src/metadata/ng_module.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ export interface NgModuleDef<T, Declarations, Imports, Exports> {
7575
* @param T the module type. In Ivy applications, this must be explicitly
7676
* provided.
7777
*/
78-
export interface ModuleWithProviders<T = any> {
78+
export interface ModuleWithProviders<
79+
T = any /** TODO(alxhub): remove default when callers pass explicit type param */> {
7980
ngModule: Type<T>;
8081
providers?: Provider[];
8182
}
8283

8384
/**
8485
* A schema definition associated with an NgModule.
85-
*
86+
*
8687
* @see `@NgModule`, `CUSTOM_ELEMENTS_SCHEMA`, `NO_ERRORS_SCHEMA`
87-
*
88+
*
8889
* @param name The name of a defined schema.
8990
*
9091
* @experimental
@@ -135,7 +136,7 @@ export interface NgModule {
135136
/**
136137
* The set of injectable objects that are available in the injector
137138
* of this module.
138-
*
139+
*
139140
* @see [Dependency Injection guide](guide/dependency-injection)
140141
* @see [NgModule guide](guide/providers)
141142
*
@@ -145,14 +146,14 @@ export interface NgModule {
145146
* into any component, directive, pipe or service that is a child of this injector.
146147
* The NgModule used for bootstrapping uses the root injector, and can provide dependencies
147148
* to any part of the app.
148-
*
149+
*
149150
* A lazy-loaded module has its own injector, typically a child of the app root injector.
150151
* Lazy-loaded services are scoped to the lazy-loaded module's injector.
151152
* If a lazy-loaded module also provides the `UserService`, any component created
152153
* within that module's context (such as by router navigation) gets the local instance
153-
* of the service, not the instance in the root injector.
154+
* of the service, not the instance in the root injector.
154155
* Components in external modules continue to receive the instance provided by their injectors.
155-
*
156+
*
156157
* ### Example
157158
*
158159
* The following example defines a class that is injected in
@@ -236,7 +237,7 @@ export interface NgModule {
236237
* ```
237238
*
238239
*/
239-
imports?: Array<Type<any>|ModuleWithProviders|any[]>;
240+
imports?: Array<Type<any>|ModuleWithProviders<{}>|any[]>;
240241

241242
/**
242243
* The set of components, directives, and pipes declared in this

packages/core/src/render3/jit/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function flatten<T>(values: any[]): T[] {
228228
return out;
229229
}
230230

231-
function expandModuleWithProviders(value: Type<any>| ModuleWithProviders): Type<any> {
231+
function expandModuleWithProviders(value: Type<any>| ModuleWithProviders<{}>): Type<any> {
232232
if (isModuleWithProviders(value)) {
233233
return value.ngModule;
234234
}
@@ -244,7 +244,7 @@ function wrapReference(value: Type<any>): R3Reference {
244244
return {value: wrapped, type: wrapped};
245245
}
246246

247-
function isModuleWithProviders(value: any): value is ModuleWithProviders {
247+
function isModuleWithProviders(value: any): value is ModuleWithProviders<{}> {
248248
return (value as{ngModule?: any}).ngModule !== undefined;
249249
}
250250

packages/forms/src/form_providers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class FormsModule {
3434
*/
3535
static withConfig(opts: {
3636
/** @deprecated as of v6 */ warnOnDeprecatedNgFormSelector?: 'never' | 'once' | 'always',
37-
}): ModuleWithProviders {
37+
}): ModuleWithProviders<FormsModule> {
3838
return {
3939
ngModule: FormsModule,
4040
providers:
@@ -48,7 +48,7 @@ export class FormsModule {
4848
* An `NgModule` that registers the directives and providers for reactive forms.
4949
*
5050
* @see [Reactive Forms Guide](/guide/reactive-forms)
51-
*
51+
*
5252
*/
5353
@NgModule({
5454
declarations: [REACTIVE_DRIVEN_DIRECTIVES],

packages/service-worker/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class ServiceWorkerModule {
7070
* workers are not supported by the browser, and the service worker will not be registered.
7171
*/
7272
static register(script: string, opts: {scope?: string; enabled?: boolean;} = {}):
73-
ModuleWithProviders {
73+
ModuleWithProviders<ServiceWorkerModule> {
7474
return {
7575
ngModule: ServiceWorkerModule,
7676
providers: [

tools/public_api_guard/common/http.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,11 +1482,11 @@ export declare class HttpClientModule {
14821482
}
14831483

14841484
export declare class HttpClientXsrfModule {
1485-
static disable(): ModuleWithProviders;
1485+
static disable(): ModuleWithProviders<HttpClientXsrfModule>;
14861486
static withOptions(options?: {
14871487
cookieName?: string;
14881488
headerName?: string;
1489-
}): ModuleWithProviders;
1489+
}): ModuleWithProviders<HttpClientXsrfModule>;
14901490
}
14911491

14921492
export interface HttpDownloadProgressEvent extends HttpProgressEvent {

tools/public_api_guard/core/core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export declare class ModuleWithComponentFactories<T> {
506506
constructor(ngModuleFactory: NgModuleFactory<T>, componentFactories: ComponentFactory<any>[]);
507507
}
508508

509-
export interface ModuleWithProviders<T = any> {
509+
export interface ModuleWithProviders<T = any /** TODO(alxhub): remove default when callers pass explicit type param */> {
510510
ngModule: Type<T>;
511511
providers?: Provider[];
512512
}

tools/public_api_guard/forms/forms.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export declare class FormGroupName extends AbstractFormGroupDirective implements
331331

332332
export declare class FormsModule {
333333
static withConfig(opts: { warnOnDeprecatedNgFormSelector?: 'never' | 'once' | 'always';
334-
}): ModuleWithProviders;
334+
}): ModuleWithProviders<FormsModule>;
335335
}
336336

337337
export declare class MaxLengthValidator implements Validator, OnChanges {

tools/public_api_guard/service-worker/service-worker.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export declare class ServiceWorkerModule {
33
static register(script: string, opts?: {
44
scope?: string;
55
enabled?: boolean;
6-
}): ModuleWithProviders;
6+
}): ModuleWithProviders<ServiceWorkerModule>;
77
}
88

99
/** @experimental */

0 commit comments

Comments
 (0)