From cbbad1b791d541093c9ffd68858fbb90d2c1af2d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 14 Sep 2018 14:55:16 -0700 Subject: [PATCH] refactor(ivy): pre-factor: set explicit type parameters for ModuleWithProviders (#25970) Ivy depends on having the generic type token later when reading the ModuleWithProviders from a .d.ts file. PR Close #25970 --- packages/common/http/src/module.ts | 4 ++-- packages/core/src/metadata/ng_module.ts | 17 +++++++++-------- packages/core/src/render3/jit/module.ts | 4 ++-- packages/forms/src/form_providers.ts | 4 ++-- packages/service-worker/src/module.ts | 2 +- tools/public_api_guard/common/http.d.ts | 4 ++-- tools/public_api_guard/core/core.d.ts | 2 +- tools/public_api_guard/forms/forms.d.ts | 2 +- .../service-worker/service-worker.d.ts | 2 +- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/common/http/src/module.ts b/packages/common/http/src/module.ts index feceb505e0..be0a79fb54 100644 --- a/packages/common/http/src/module.ts +++ b/packages/common/http/src/module.ts @@ -100,7 +100,7 @@ export class HttpClientXsrfModule { /** * Disable the default XSRF protection. */ - static disable(): ModuleWithProviders { + static disable(): ModuleWithProviders { return { ngModule: HttpClientXsrfModule, providers: [ @@ -120,7 +120,7 @@ export class HttpClientXsrfModule { static withOptions(options: { cookieName?: string, headerName?: string, - } = {}): ModuleWithProviders { + } = {}): ModuleWithProviders { return { ngModule: HttpClientXsrfModule, providers: [ diff --git a/packages/core/src/metadata/ng_module.ts b/packages/core/src/metadata/ng_module.ts index 1ce2ad1467..d2ade2a309 100644 --- a/packages/core/src/metadata/ng_module.ts +++ b/packages/core/src/metadata/ng_module.ts @@ -75,16 +75,17 @@ export interface NgModuleDef { * @param T the module type. In Ivy applications, this must be explicitly * provided. */ -export interface ModuleWithProviders { +export interface ModuleWithProviders< + T = any /** TODO(alxhub): remove default when callers pass explicit type param */> { ngModule: Type; providers?: Provider[]; } /** * A schema definition associated with an NgModule. - * + * * @see `@NgModule`, `CUSTOM_ELEMENTS_SCHEMA`, `NO_ERRORS_SCHEMA` - * + * * @param name The name of a defined schema. * * @experimental @@ -135,7 +136,7 @@ export interface NgModule { /** * The set of injectable objects that are available in the injector * of this module. - * + * * @see [Dependency Injection guide](guide/dependency-injection) * @see [NgModule guide](guide/providers) * @@ -145,14 +146,14 @@ export interface NgModule { * into any component, directive, pipe or service that is a child of this injector. * The NgModule used for bootstrapping uses the root injector, and can provide dependencies * to any part of the app. - * + * * A lazy-loaded module has its own injector, typically a child of the app root injector. * Lazy-loaded services are scoped to the lazy-loaded module's injector. * If a lazy-loaded module also provides the `UserService`, any component created * within that module's context (such as by router navigation) gets the local instance - * of the service, not the instance in the root injector. + * of the service, not the instance in the root injector. * Components in external modules continue to receive the instance provided by their injectors. - * + * * ### Example * * The following example defines a class that is injected in @@ -236,7 +237,7 @@ export interface NgModule { * ``` * */ - imports?: Array|ModuleWithProviders|any[]>; + imports?: Array|ModuleWithProviders<{}>|any[]>; /** * The set of components, directives, and pipes declared in this diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 4a3e853491..d5dad0ee7b 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -228,7 +228,7 @@ function flatten(values: any[]): T[] { return out; } -function expandModuleWithProviders(value: Type| ModuleWithProviders): Type { +function expandModuleWithProviders(value: Type| ModuleWithProviders<{}>): Type { if (isModuleWithProviders(value)) { return value.ngModule; } @@ -244,7 +244,7 @@ function wrapReference(value: Type): R3Reference { return {value: wrapped, type: wrapped}; } -function isModuleWithProviders(value: any): value is ModuleWithProviders { +function isModuleWithProviders(value: any): value is ModuleWithProviders<{}> { return (value as{ngModule?: any}).ngModule !== undefined; } diff --git a/packages/forms/src/form_providers.ts b/packages/forms/src/form_providers.ts index e641363e39..60db1042cf 100644 --- a/packages/forms/src/form_providers.ts +++ b/packages/forms/src/form_providers.ts @@ -34,7 +34,7 @@ export class FormsModule { */ static withConfig(opts: { /** @deprecated as of v6 */ warnOnDeprecatedNgFormSelector?: 'never' | 'once' | 'always', - }): ModuleWithProviders { + }): ModuleWithProviders { return { ngModule: FormsModule, providers: @@ -48,7 +48,7 @@ export class FormsModule { * An `NgModule` that registers the directives and providers for reactive forms. * * @see [Reactive Forms Guide](/guide/reactive-forms) - * + * */ @NgModule({ declarations: [REACTIVE_DRIVEN_DIRECTIVES], diff --git a/packages/service-worker/src/module.ts b/packages/service-worker/src/module.ts index 1947582891..4456abd475 100644 --- a/packages/service-worker/src/module.ts +++ b/packages/service-worker/src/module.ts @@ -70,7 +70,7 @@ export class ServiceWorkerModule { * workers are not supported by the browser, and the service worker will not be registered. */ static register(script: string, opts: {scope?: string; enabled?: boolean;} = {}): - ModuleWithProviders { + ModuleWithProviders { return { ngModule: ServiceWorkerModule, providers: [ diff --git a/tools/public_api_guard/common/http.d.ts b/tools/public_api_guard/common/http.d.ts index 370d020052..95a42ec225 100644 --- a/tools/public_api_guard/common/http.d.ts +++ b/tools/public_api_guard/common/http.d.ts @@ -1482,11 +1482,11 @@ export declare class HttpClientModule { } export declare class HttpClientXsrfModule { - static disable(): ModuleWithProviders; + static disable(): ModuleWithProviders; static withOptions(options?: { cookieName?: string; headerName?: string; - }): ModuleWithProviders; + }): ModuleWithProviders; } export interface HttpDownloadProgressEvent extends HttpProgressEvent { diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 7a76067362..d710f2e04c 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -506,7 +506,7 @@ export declare class ModuleWithComponentFactories { constructor(ngModuleFactory: NgModuleFactory, componentFactories: ComponentFactory[]); } -export interface ModuleWithProviders { +export interface ModuleWithProviders { ngModule: Type; providers?: Provider[]; } diff --git a/tools/public_api_guard/forms/forms.d.ts b/tools/public_api_guard/forms/forms.d.ts index 49695f77f5..97d05e1cd5 100644 --- a/tools/public_api_guard/forms/forms.d.ts +++ b/tools/public_api_guard/forms/forms.d.ts @@ -331,7 +331,7 @@ export declare class FormGroupName extends AbstractFormGroupDirective implements export declare class FormsModule { static withConfig(opts: { warnOnDeprecatedNgFormSelector?: 'never' | 'once' | 'always'; - }): ModuleWithProviders; + }): ModuleWithProviders; } export declare class MaxLengthValidator implements Validator, OnChanges { diff --git a/tools/public_api_guard/service-worker/service-worker.d.ts b/tools/public_api_guard/service-worker/service-worker.d.ts index e05787c01a..ac382b9b98 100644 --- a/tools/public_api_guard/service-worker/service-worker.d.ts +++ b/tools/public_api_guard/service-worker/service-worker.d.ts @@ -3,7 +3,7 @@ export declare class ServiceWorkerModule { static register(script: string, opts?: { scope?: string; enabled?: boolean; - }): ModuleWithProviders; + }): ModuleWithProviders; } /** @experimental */