refactor: replace any[] with Provider[] where possible
This commit is contained in:

committed by
Victor Berchet

parent
eb7d8c702c
commit
ea2e5521e8
@ -14,7 +14,7 @@ import {ApplicationInitStatus} from './application_init';
|
||||
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
|
||||
import {ChangeDetectorRef} from './change_detection/change_detector_ref';
|
||||
import {Console} from './console';
|
||||
import {Injectable, Injector, OpaqueToken, Optional, ReflectiveInjector} from './di';
|
||||
import {Injectable, Injector, OpaqueToken, Optional, Provider, ReflectiveInjector} from './di';
|
||||
import {CompilerFactory, CompilerOptions} from './linker/compiler';
|
||||
import {ComponentFactory, ComponentRef} from './linker/component_factory';
|
||||
import {ComponentFactoryResolver} from './linker/component_factory_resolver';
|
||||
@ -81,7 +81,7 @@ export function createPlatform(injector: Injector): PlatformRef {
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export type PlatformFactory = (extraProviders?: any[]) => PlatformRef;
|
||||
export type PlatformFactory = (extraProviders?: Provider[]) => PlatformRef;
|
||||
|
||||
/**
|
||||
* Creates a factory for a platform
|
||||
@ -89,9 +89,10 @@ export type PlatformFactory = (extraProviders?: any[]) => PlatformRef;
|
||||
* @experimental APIs related to application bootstrap are currently under review.
|
||||
*/
|
||||
export function createPlatformFactory(
|
||||
parentPlaformFactory: PlatformFactory, name: string, providers: any[] = []): PlatformFactory {
|
||||
parentPlaformFactory: PlatformFactory, name: string,
|
||||
providers: Provider[] = []): PlatformFactory {
|
||||
const marker = new OpaqueToken(`Platform: ${name}`);
|
||||
return (extraProviders: any[] = []) => {
|
||||
return (extraProviders: Provider[] = []) => {
|
||||
if (!getPlatform()) {
|
||||
if (parentPlaformFactory) {
|
||||
parentPlaformFactory(
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {AnimationEntryMetadata} from '../animation/metadata';
|
||||
import {ChangeDetectionStrategy} from '../change_detection/constants';
|
||||
import {InjectableMetadata} from '../di/metadata';
|
||||
import {InjectableMetadata, Provider} from '../di';
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {ViewEncapsulation} from './view';
|
||||
@ -668,8 +668,8 @@ export class DirectiveMetadata extends InjectableMetadata implements DirectiveMe
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
get providers(): any[] { return this._providers; }
|
||||
private _providers: any[];
|
||||
get providers(): Provider[] { return this._providers; }
|
||||
private _providers: Provider[];
|
||||
|
||||
/**
|
||||
* Defines the name that can be used in the template to assign this directive to a variable.
|
||||
@ -835,8 +835,8 @@ export class ComponentMetadata extends DirectiveMetadata implements ComponentMet
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
get viewProviders(): any[] { return this._viewProviders; }
|
||||
private _viewProviders: any[];
|
||||
get viewProviders(): Provider[] { return this._viewProviders; }
|
||||
private _viewProviders: Provider[];
|
||||
|
||||
/**
|
||||
* The module id of the module that contains the component.
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectableMetadata} from '../di/metadata';
|
||||
import {InjectableMetadata, Provider} from '../di';
|
||||
import {Type} from '../type';
|
||||
|
||||
/**
|
||||
@ -16,7 +16,7 @@ import {Type} from '../type';
|
||||
*/
|
||||
export interface ModuleWithProviders {
|
||||
ngModule: Type<any>;
|
||||
providers?: any[];
|
||||
providers?: Provider[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@ export const NO_ERRORS_SCHEMA: SchemaMetadata = {
|
||||
* @stable
|
||||
*/
|
||||
export interface NgModuleMetadataType {
|
||||
providers?: any[];
|
||||
providers?: Provider[];
|
||||
declarations?: Array<Type<any>|any[]>;
|
||||
imports?: Array<Type<any>|ModuleWithProviders|any[]>;
|
||||
exports?: Array<Type<any>|any[]>;
|
||||
@ -93,8 +93,8 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
get providers(): any[] { return this._providers; }
|
||||
private _providers: any[];
|
||||
get providers(): Provider[] { return this._providers; }
|
||||
private _providers: Provider[];
|
||||
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {PlatformRef, PlatformRef_, createPlatformFactory} from './application_ref';
|
||||
import {Console} from './console';
|
||||
import {Provider} from './di';
|
||||
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './di';
|
||||
import {Reflector, reflector} from './reflection/reflection';
|
||||
import {ReflectorReader} from './reflection/reflector_reader';
|
||||
import {TestabilityRegistry} from './testability/testability';
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Inject, InjectMetadata, Injectable, Injector, Optional, ReflectiveInjector, ReflectiveKey, SelfMetadata, forwardRef} from '@angular/core';
|
||||
import {Inject, InjectMetadata, Injectable, Injector, Optional, Provider, ReflectiveInjector, ReflectiveKey, SelfMetadata, forwardRef} from '@angular/core';
|
||||
import {DependencyMetadata} from '@angular/core/src/di/metadata';
|
||||
import {ReflectiveInjectorDynamicStrategy, ReflectiveInjectorInlineStrategy, ReflectiveInjector_, ReflectiveProtoInjector} from '@angular/core/src/di/reflective_injector';
|
||||
import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider';
|
||||
@ -93,7 +93,7 @@ export function main() {
|
||||
strategyClass: ReflectiveInjectorDynamicStrategy
|
||||
}].forEach((context) => {
|
||||
function createInjector(
|
||||
providers: any[], parent: ReflectiveInjector = null): ReflectiveInjector_ {
|
||||
providers: Provider[], parent: ReflectiveInjector = null): ReflectiveInjector_ {
|
||||
var resolvedProviders = ReflectiveInjector.resolve(providers.concat(context['providers']));
|
||||
if (isPresent(parent)) {
|
||||
return <ReflectiveInjector_>parent.createChildFromResolved(resolvedProviders);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, SelfMetadata, Type, forwardRef} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, SelfMetadata, Type, forwardRef} from '@angular/core';
|
||||
import {Console} from '@angular/core/src/console';
|
||||
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
@ -567,7 +567,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
let moduleType: any = null;
|
||||
|
||||
|
||||
function createInjector(providers: any[], parent: Injector = null): Injector {
|
||||
function createInjector(providers: Provider[], parent: Injector = null): Injector {
|
||||
@NgModule({providers: providers})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -6,9 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgClass, NgIf} from '@angular/common';
|
||||
import {Component, Injector, OpaqueToken, Pipe, PipeTransform, forwardRef} from '@angular/core';
|
||||
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
||||
import {Component, Injector, OpaqueToken, Pipe, PipeTransform, Provider} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
@ -84,7 +82,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
});
|
||||
|
||||
describe('providers', () => {
|
||||
function createInjector(providers: any[]): Injector {
|
||||
function createInjector(providers: Provider[]): Injector {
|
||||
TestBed.overrideComponent(MyComp1, {add: {providers}});
|
||||
return TestBed.createComponent(MyComp1).componentInstance.injector;
|
||||
}
|
||||
|
@ -6,15 +6,12 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgFor, NgIf} from '@angular/common';
|
||||
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, forwardRef} from '@angular/core';
|
||||
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
||||
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Provider, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, forwardRef} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {isBlank} from '../../src/facade/lang';
|
||||
|
||||
@Directive({selector: '[simpleDirective]'})
|
||||
class SimpleDirective {
|
||||
@ -194,7 +191,7 @@ class TestComp {
|
||||
|
||||
export function main() {
|
||||
function createComponentFixture<T>(
|
||||
template: string, providers: any[] = null, comp: Type<T> = null): ComponentFixture<T> {
|
||||
template: string, providers: Provider[] = null, comp: Type<T> = null): ComponentFixture<T> {
|
||||
if (!comp) {
|
||||
comp = <any>TestComp;
|
||||
}
|
||||
@ -206,7 +203,7 @@ export function main() {
|
||||
}
|
||||
|
||||
function createComponent(
|
||||
template: string, providers: any[] = null, comp: Type<any> = null): DebugElement {
|
||||
template: string, providers: Provider[] = null, comp: Type<any> = null): DebugElement {
|
||||
const fixture = createComponentFixture(template, providers, comp);
|
||||
fixture.detectChanges();
|
||||
return fixture.debugElement;
|
||||
|
Reference in New Issue
Block a user