refactor(Type): merge Type and ConcreType<?> into Type<?> (#10616)

Closes #9729

BREAKING CHANGE:

`Type` is now `Type<T>` which means that in most cases you have to
use `Type<any>` in place of `Type`.

We don't expect that any user applications use the `Type` type.
This commit is contained in:
Miško Hevery
2016-08-10 18:21:28 -07:00
committed by vikerman
parent 6f4ee6101c
commit b96869afd2
91 changed files with 637 additions and 714 deletions

View File

@ -6,8 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '../src/facade/lang';
import {ApplicationInitStatus} from './application_init';
import {ApplicationRef, ApplicationRef_, isDevMode} from './application_ref';
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
@ -18,6 +16,7 @@ import {ComponentResolver} from './linker/component_resolver';
import {DynamicComponentLoader, DynamicComponentLoader_} from './linker/dynamic_component_loader';
import {ViewUtils} from './linker/view_utils';
import {NgModule} from './metadata';
import {Type} from './type';
export function _iterableDiffersFactory() {
return defaultIterableDiffers;
@ -33,7 +32,7 @@ export function _keyValueDiffersFactory() {
*
* @deprecated Include `ApplicationModule` instead.
*/
export const APPLICATION_COMMON_PROVIDERS: Array<Type|{[k: string]: any}|any[]> = [];
export const APPLICATION_COMMON_PROVIDERS: Array<Type<any>|{[k: string]: any}|any[]> = [];
/**
* This module includes the providers of @angular/core that are needed

View File

@ -8,7 +8,7 @@
import {ListWrapper} from '../src/facade/collection';
import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions';
import {ConcreteType, Type, isBlank, isPresent, isPromise, stringify} from '../src/facade/lang';
import {isBlank, isPresent, isPromise, stringify} from '../src/facade/lang';
import {ApplicationInitStatus} from './application_init';
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
@ -22,6 +22,7 @@ import {ComponentResolver} from './linker/component_resolver';
import {NgModuleFactory, NgModuleInjector, NgModuleRef} from './linker/ng_module_factory';
import {WtfScopeFn, wtfCreateScope, wtfLeave} from './profile/profile';
import {Testability, TestabilityRegistry} from './testability/testability';
import {Type} from './type';
import {NgZone, NgZoneError} from './zone/ng_zone';
var _devMode: boolean = true;
@ -182,7 +183,7 @@ export function coreBootstrap<C>(
* @deprecated Use {@link bootstrapModule} instead.
*/
export function coreLoadAndBootstrap(
componentType: Type, injector: Injector): Promise<ComponentRef<any>> {
componentType: Type<any>, injector: Injector): Promise<ComponentRef<any>> {
throw new BaseException('coreLoadAndBootstrap is deprecated. Use bootstrapModule instead.');
}
@ -239,9 +240,8 @@ export abstract class PlatformRef {
* ```
* @stable
*/
bootstrapModule<M>(
moduleType: ConcreteType<M>,
compilerOptions: CompilerOptions|CompilerOptions[] = []): Promise<NgModuleRef<M>> {
bootstrapModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions|CompilerOptions[] = []):
Promise<NgModuleRef<M>> {
throw unimplemented();
}
@ -373,14 +373,13 @@ export class PlatformRef_ extends PlatformRef {
});
}
bootstrapModule<M>(
moduleType: ConcreteType<M>,
compilerOptions: CompilerOptions|CompilerOptions[] = []): Promise<NgModuleRef<M>> {
bootstrapModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions|CompilerOptions[] = []):
Promise<NgModuleRef<M>> {
return this._bootstrapModuleWithZone(moduleType, compilerOptions, null);
}
private _bootstrapModuleWithZone<M>(
moduleType: ConcreteType<M>, compilerOptions: CompilerOptions|CompilerOptions[] = [],
moduleType: Type<M>, compilerOptions: CompilerOptions|CompilerOptions[] = [],
ngZone: NgZone): Promise<NgModuleRef<M>> {
const compilerFactory: CompilerFactory = this.injector.get(CompilerFactory);
const compiler = compilerFactory.createCompiler(
@ -455,7 +454,7 @@ export abstract class ApplicationRef {
* ### Example
* {@example core/ts/platform/platform.ts region='longform'}
*/
abstract bootstrap<C>(componentFactory: ComponentFactory<C>|ConcreteType<C>): ComponentRef<C>;
abstract bootstrap<C>(componentFactory: ComponentFactory<C>|Type<C>): ComponentRef<C>;
/**
* Retrieve the application {@link Injector}.
@ -496,7 +495,7 @@ export abstract class ApplicationRef {
* Get a list of component types registered to this application.
* This list is populated even before the component is created.
*/
get componentTypes(): Type[] { return <Type[]>unimplemented(); };
get componentTypes(): Type<any>[] { return <Type<any>[]>unimplemented(); };
/**
* Get a list of components registered to this application.
@ -515,7 +514,7 @@ export class ApplicationRef_ extends ApplicationRef {
*/
private _disposeListeners: Function[] = [];
private _rootComponents: ComponentRef<any>[] = [];
private _rootComponentTypes: Type[] = [];
private _rootComponentTypes: Type<any>[] = [];
private _changeDetectorRefs: ChangeDetectorRef[] = [];
private _runningTick: boolean = false;
private _enforceNoNewChanges: boolean = false;
@ -567,7 +566,7 @@ export class ApplicationRef_ extends ApplicationRef {
() => _callAndReportToExceptionHandler(this._exceptionHandler, <any>callback));
}
bootstrap<C>(componentOrFactory: ComponentFactory<C>|ConcreteType<C>): ComponentRef<C> {
bootstrap<C>(componentOrFactory: ComponentFactory<C>|Type<C>): ComponentRef<C> {
if (!this._initStatus.done) {
throw new BaseException(
'Cannot bootstrap as there are still asynchronous initializers running. Bootstrap components in the `ngDoBootstrap` method of the root module.');
@ -655,7 +654,7 @@ export class ApplicationRef_ extends ApplicationRef {
*/
dispose(): void { this.ngOnDestroy(); }
get componentTypes(): Type[] { return this._rootComponentTypes; }
get componentTypes(): Type<any>[] { return this._rootComponentTypes; }
get components(): ComponentRef<any>[] { return this._rootComponents; }
}

View File

@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type, isFunction, stringify} from '../facade/lang';
import {isFunction, stringify} from '../facade/lang';
import {Type} from '../type';
/**
@ -31,10 +32,10 @@ export interface ForwardRefFn { (): any; }
* {@example core/di/ts/forward_ref/forward_ref.ts region='forward_ref'}
* @experimental
*/
export function forwardRef(forwardRefFn: ForwardRefFn): Type {
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
(<any>forwardRefFn).__forward_ref__ = forwardRef;
(<any>forwardRefFn).toString = function() { return stringify(this()); };
return (<Type><any>forwardRefFn);
return (<Type<any>><any>forwardRefFn);
}
/**

View File

@ -7,7 +7,8 @@
*/
import {BaseException} from '../facade/exceptions';
import {Type, isBlank, isFunction, isType, normalizeBool, stringify} from '../facade/lang';
import {isBlank, isFunction, isType, normalizeBool, stringify} from '../facade/lang';
import {Type} from '../type';
/**
@ -61,7 +62,7 @@ export class Provider {
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
* ```
*/
useClass: Type;
useClass: Type<any>;
/**
* Binds a DI token to a value.
@ -157,7 +158,7 @@ export class Provider {
_multi: boolean;
constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type,
useClass?: Type<any>,
useValue?: any,
useExisting?: any,
useFactory?: Function,
@ -213,7 +214,7 @@ export class Provider {
*/
export class Binding extends Provider {
constructor(token: any, {toClass, toValue, toAlias, toFactory, deps, multi}: {
toClass?: Type,
toClass?: Type<any>,
toValue?: any,
toAlias?: any,
toFactory: Function, deps?: Object[], multi?: boolean
@ -301,7 +302,7 @@ export class ProviderBuilder {
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
* ```
*/
toClass(type: Type): Provider {
toClass(type: Type<any>): Provider {
if (!isType(type)) {
throw new BaseException(
`Trying to create a class provider but "${stringify(type)}" is not a class!`);
@ -396,7 +397,7 @@ export class ProviderBuilder {
* @deprecated
*/
export function provide(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
useClass?: Type,
useClass?: Type<any>,
useValue?: any,
useExisting?: any,
useFactory?: Function,

View File

@ -8,7 +8,8 @@
import {ListWrapper} from '../facade/collection';
import {BaseException, WrappedException} from '../facade/exceptions';
import {Type, isBlank, stringify} from '../facade/lang';
import {isBlank, stringify} from '../facade/lang';
import {Type} from '../type';
import {Provider} from './provider';
import {ReflectiveInjector} from './reflective_injector';
@ -225,11 +226,11 @@ export class InvalidProviderError extends BaseException {
* @stable
*/
export class NoAnnotationError extends BaseException {
constructor(typeOrFunc: Type|Function, params: any[][]) {
constructor(typeOrFunc: Type<any>|Function, params: any[][]) {
super(NoAnnotationError._genMessage(typeOrFunc, params));
}
private static _genMessage(typeOrFunc: Type|Function, params: any[][]) {
private static _genMessage(typeOrFunc: Type<any>|Function, params: any[][]) {
var signature: string[] = [];
for (var i = 0, ii = params.length; i < ii; i++) {
var parameter = params[i];

View File

@ -8,7 +8,7 @@
import {ListWrapper} from '../facade/collection';
import {BaseException, unimplemented} from '../facade/exceptions';
import {Type} from '../facade/lang';
import {Type} from '../type';
import {Injector, THROW_IF_NOT_FOUND} from './injector';
import {SelfMetadata, SkipSelfMetadata} from './metadata';
@ -17,7 +17,7 @@ import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProv
import {ReflectiveKey} from './reflective_key';
import {ReflectiveDependency, ResolvedReflectiveFactory, ResolvedReflectiveProvider, resolveReflectiveProviders} from './reflective_provider';
var __unused: Type; // avoid unused import when Type union types are erased
var __unused: Type<any>; // avoid unused import when Type union types are erased
// Threshold for the dynamic version
const _MAX_CONSTRUCTION_COUNTER = 10;
@ -392,7 +392,7 @@ export abstract class ReflectiveInjector implements Injector {
*
* See {@link ReflectiveInjector#fromResolvedProviders} for more info.
*/
static resolve(providers: Array<Type|Provider|{[k: string]: any}|any[]>):
static resolve(providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>):
ResolvedReflectiveProvider[] {
return resolveReflectiveProviders(providers);
}
@ -424,7 +424,7 @@ export abstract class ReflectiveInjector implements Injector {
* See {@link Injector#resolve} and {@link Injector#fromResolvedProviders}.
*/
static resolveAndCreate(
providers: Array<Type|Provider|{[k: string]: any}|any[]>,
providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>,
parent: Injector = null): ReflectiveInjector {
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
return ReflectiveInjector.fromResolvedProviders(ResolvedReflectiveProviders, parent);
@ -516,7 +516,7 @@ export abstract class ReflectiveInjector implements Injector {
* because it needs to resolve the passed-in providers first.
* See {@link Injector#resolve} and {@link Injector#createChildFromResolved}.
*/
resolveAndCreateChild(providers: Array<Type|Provider|{[k: string]: any}|any[]>):
resolveAndCreateChild(providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>):
ReflectiveInjector {
return unimplemented();
}
@ -574,7 +574,7 @@ export abstract class ReflectiveInjector implements Injector {
* expect(car).not.toBe(injector.resolveAndInstantiate(Car));
* ```
*/
resolveAndInstantiate(provider: Type|Provider): any { return unimplemented(); }
resolveAndInstantiate(provider: Type<any>|Provider): any { return unimplemented(); }
/**
* Instantiates an object using a resolved provider in the context of the injector.
@ -644,7 +644,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
*/
get internalStrategy(): any { return this._strategy; }
resolveAndCreateChild(providers: Array<Type|Provider|any[]>): ReflectiveInjector {
resolveAndCreateChild(providers: Array<Type<any>|Provider|any[]>): ReflectiveInjector {
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
return this.createChildFromResolved(ResolvedReflectiveProviders);
}
@ -656,7 +656,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return inj;
}
resolveAndInstantiate(provider: Type|Provider): any {
resolveAndInstantiate(provider: Type<any>|Provider): any {
return this.instantiateResolved(ReflectiveInjector.resolve([provider])[0]);
}

View File

@ -7,8 +7,9 @@
*/
import {ListWrapper, MapWrapper} from '../facade/collection';
import {Type, isArray, isBlank, isPresent} from '../facade/lang';
import {isArray, isBlank, isPresent} from '../facade/lang';
import {reflector} from '../reflection/reflection';
import {Type} from '../type';
import {resolveForwardRef} from './forward_ref';
import {DependencyMetadata, HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata';
@ -18,6 +19,7 @@ import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoA
import {ReflectiveKey} from './reflective_key';
/**
* `Dependency` is used by the framework to extend DI.
* This is internal to Angular and should not be used directly.
@ -54,7 +56,7 @@ const _EMPTY_LIST: any[] = [];
*/
export interface ResolvedReflectiveProvider {
/**
* A key, usually a `Type`.
* A key, usually a `Type<any>`.
*/
key: ReflectiveKey;
@ -140,7 +142,7 @@ export function resolveReflectiveProvider(provider: Provider): ResolvedReflectiv
* Resolve a list of Providers.
*/
export function resolveReflectiveProviders(
providers: Array<Type|Provider|{[k: string]: any}|any[]>): ResolvedReflectiveProvider[] {
providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>): ResolvedReflectiveProvider[] {
var normalized = _normalizeProviders(providers, []);
var resolved = normalized.map(resolveReflectiveProvider);
return MapWrapper.values(
@ -185,7 +187,7 @@ export function mergeResolvedReflectiveProviders(
}
function _normalizeProviders(
providers: Array<Type|Provider|{[k: string]: any}|ProviderBuilder|any[]>,
providers: Array<Type<any>|Provider|{[k: string]: any}|ProviderBuilder|any[]>,
res: Provider[]): Provider[] {
providers.forEach(b => {
if (b instanceof Type) {

View File

@ -6,23 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injector, OpaqueToken} from '../di';
import {BaseException, unimplemented} from '../facade/exceptions';
import {ConcreteType, Type, stringify} from '../facade/lang';
import {NgModuleMetadata, ViewEncapsulation} from '../metadata';
import {OpaqueToken} from '../di';
import {BaseException} from '../facade/exceptions';
import {stringify} from '../facade/lang';
import {ViewEncapsulation} from '../metadata';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
import {ComponentResolver} from './component_resolver';
import {NgModuleFactory} from './ng_module_factory';
/**
* Indicates that a component is still being loaded in a synchronous compile.
*
* @stable
*/
export class ComponentStillLoadingError extends BaseException {
constructor(public compType: Type) {
constructor(public compType: Type<any>) {
super(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
}
}
@ -57,7 +58,7 @@ export class Compiler {
/**
* Loads the template and styles of a component and returns the associated `ComponentFactory`.
*/
compileComponentAsync<T>(component: ConcreteType<T>, ngModule: Type = null):
compileComponentAsync<T>(component: Type<T>, ngModule: Type<any> = null):
Promise<ComponentFactory<T>> {
throw _throwError();
}
@ -65,7 +66,7 @@ export class Compiler {
* Compiles the given component. All templates have to be either inline or compiled via
* `compileComponentAsync` before. Otherwise throws a {@link ComponentStillLoadingError}.
*/
compileComponentSync<T>(component: ConcreteType<T>, ngModule: Type = null): ComponentFactory<T> {
compileComponentSync<T>(component: Type<T>, ngModule: Type<any> = null): ComponentFactory<T> {
throw _throwError();
}
/**
@ -73,27 +74,24 @@ export class Compiler {
* in `entryComponents`
* have to be inlined. Otherwise throws a {@link ComponentStillLoadingError}.
*/
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> { throw _throwError(); }
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> { throw _throwError(); }
/**
* Compiles the given NgModule and all of its components
*/
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
throw _throwError();
}
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> { throw _throwError(); }
/**
* Same as {@link compileModuleSync} put also creates ComponentFactories for all components.
*/
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
ModuleWithComponentFactories<T> {
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
throw _throwError();
}
/**
* Same as {@link compileModuleAsync} put also creates ComponentFactories for all components.
*/
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
Promise<ModuleWithComponentFactories<T>> {
throw _throwError();
}
@ -106,7 +104,7 @@ export class Compiler {
/**
* Clears the cache for the given component/ngModule.
*/
clearCacheFor(type: Type) {}
clearCacheFor(type: Type<any>) {}
}
/**

View File

@ -9,7 +9,8 @@
import {ChangeDetectorRef} from '../change_detection/change_detection';
import {Injector} from '../di/injector';
import {unimplemented} from '../facade/exceptions';
import {Type, isBlank} from '../facade/lang';
import {isBlank} from '../facade/lang';
import {Type} from '../type';
import {AppElement} from './element';
import {ElementRef} from './element_ref';
import {ViewRef} from './view_ref';
@ -53,7 +54,7 @@ export abstract class ComponentRef<C> {
/**
* The component type.
*/
get componentType(): Type { return unimplemented(); }
get componentType(): Type<any> { return unimplemented(); }
/**
* Destroys the component instance and all of the data structures associated with it.
@ -67,13 +68,13 @@ export abstract class ComponentRef<C> {
}
export class ComponentRef_<C> extends ComponentRef<C> {
constructor(private _hostElement: AppElement, private _componentType: Type) { super(); }
constructor(private _hostElement: AppElement, private _componentType: Type<any>) { super(); }
get location(): ElementRef { return this._hostElement.elementRef; }
get injector(): Injector { return this._hostElement.injector; }
get instance(): C { return this._hostElement.component; };
get hostView(): ViewRef { return this._hostElement.parentView.ref; };
get changeDetectorRef(): ChangeDetectorRef { return this._hostElement.parentView.ref; };
get componentType(): Type { return this._componentType; }
get componentType(): Type<any> { return this._componentType; }
destroy(): void { this._hostElement.parentView.destroy(); }
onDestroy(callback: Function): void { this.hostView.onDestroy(callback); }
@ -89,9 +90,9 @@ const EMPTY_CONTEXT = new Object();
*/
export class ComponentFactory<C> {
constructor(
public selector: string, private _viewFactory: Function, private _componentType: Type) {}
public selector: string, private _viewFactory: Function, private _componentType: Type<any>) {}
get componentType(): Type { return this._componentType; }
get componentType(): Type<any> { return this._componentType; }
/**
* Creates a new component.

View File

@ -7,9 +7,12 @@
*/
import {BaseException} from '../facade/exceptions';
import {ConcreteType, stringify} from '../facade/lang';
import {stringify} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
/**
* @stable
*/
@ -30,7 +33,7 @@ class _NullComponentFactoryResolver implements ComponentFactoryResolver {
*/
export abstract class ComponentFactoryResolver {
static NULL: ComponentFactoryResolver = new _NullComponentFactoryResolver();
abstract resolveComponentFactory<T>(component: ConcreteType<T>): ComponentFactory<T>;
abstract resolveComponentFactory<T>(component: Type<T>): ComponentFactory<T>;
}
export class CodegenComponentFactoryResolver implements ComponentFactoryResolver {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
/**
@ -25,6 +25,6 @@ export abstract class ComponentResolver {
'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.';
abstract resolveComponent(component: Type|string): Promise<ComponentFactory<any>>;
abstract resolveComponent(component: Type<any>|string): Promise<ComponentFactory<any>>;
abstract clearCache(): void;
}

View File

@ -7,8 +7,8 @@
*/
import {Injectable, Injector, ReflectiveInjector, ResolvedReflectiveProvider} from '../di';
import {Type, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
import {Type} from '../type';
import {Compiler} from './compiler';
import {ComponentRef} from './component_factory';
import {ViewContainerRef} from './view_container_ref';
@ -70,8 +70,8 @@ export abstract class DynamicComponentLoader {
* ```
*/
abstract loadAsRoot(
type: Type, overrideSelectorOrNode: string|any, injector: Injector, onDispose?: () => void,
projectableNodes?: any[][]): Promise<ComponentRef<any>>;
type: Type<any>, overrideSelectorOrNode: string|any, injector: Injector,
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef<any>>;
/**
@ -115,7 +115,7 @@ export abstract class DynamicComponentLoader {
* ```
*/
abstract loadNextToLocation(
type: Type, location: ViewContainerRef, providers?: ResolvedReflectiveProvider[],
type: Type<any>, location: ViewContainerRef, providers?: ResolvedReflectiveProvider[],
projectableNodes?: any[][]): Promise<ComponentRef<any>>;
}
@ -124,8 +124,8 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
constructor(private _compiler: Compiler) { super(); }
loadAsRoot(
type: Type, overrideSelectorOrNode: string|any, injector: Injector, onDispose?: () => void,
projectableNodes?: any[][]): Promise<ComponentRef<any>> {
type: Type<any>, overrideSelectorOrNode: string|any, injector: Injector,
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef<any>> {
return this._compiler.compileComponentAsync(<any>type).then(componentFactory => {
var componentRef = componentFactory.create(
injector, projectableNodes,
@ -138,7 +138,7 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
}
loadNextToLocation(
type: Type, location: ViewContainerRef, providers: ResolvedReflectiveProvider[] = null,
type: Type<any>, location: ViewContainerRef, providers: ResolvedReflectiveProvider[] = null,
projectableNodes: any[][] = null): Promise<ComponentRef<any>> {
return this._compiler.compileComponentAsync(<any>type).then(componentFactory => {
var contextInjector = location.parentInjector;

View File

@ -8,8 +8,8 @@
import {Injector, THROW_IF_NOT_FOUND} from '../di/injector';
import {BaseException, unimplemented} from '../facade/exceptions';
import {ConcreteType, stringify} from '../facade/lang';
import {stringify} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
import {CodegenComponentFactoryResolver, ComponentFactoryResolver} from './component_factory_resolver';
@ -57,9 +57,9 @@ export abstract class NgModuleRef<T> {
export class NgModuleFactory<T> {
constructor(
private _injectorClass: {new (parentInjector: Injector): NgModuleInjector<T>},
private _moduleype: ConcreteType<T>) {}
private _moduleype: Type<T>) {}
get moduleType(): ConcreteType<T> { return this._moduleype; }
get moduleType(): Type<T> { return this._moduleype; }
create(parentInjector: Injector): NgModuleRef<T> {
if (!parentInjector) {

View File

@ -8,8 +8,8 @@
import {Console} from '../console';
import {Injectable} from '../di';
import {Type, global, isString} from '../facade/lang';
import {global, isString} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
import {ComponentResolver} from './component_resolver';
@ -26,7 +26,7 @@ const _SEPARATOR = '#';
export class SystemJsComponentResolver implements ComponentResolver {
constructor(private _resolver: ComponentResolver, private _console: Console) {}
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
resolveComponent(componentType: string|Type<any>): Promise<ComponentFactory<any>> {
if (isString(componentType)) {
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
let [module, component] = componentType.split(_SEPARATOR);
@ -60,7 +60,7 @@ const FACTORY_CLASS_SUFFIX = 'NgFactory';
@Injectable()
export class SystemJsCmpFactoryResolver implements ComponentResolver {
constructor(private _console: Console) {}
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
resolveComponent(componentType: string|Type<any>): Promise<ComponentFactory<any>> {
if (isString(componentType)) {
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
let [module, factory] = componentType.split(_SEPARATOR);

View File

@ -11,14 +11,11 @@
* to be used by the decorator versions of these annotations.
*/
import {ChangeDetectionStrategy} from '../src/change_detection/change_detection';
import {Type} from '../src/facade/lang';
import {AnimationEntryMetadata} from './animation/metadata';
import {AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
import {ComponentMetadata, ComponentMetadataType, DirectiveMetadata, DirectiveMetadataType, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata, PipeMetadataType} from './metadata/directives';
import {ModuleWithProviders, NgModuleMetadata, NgModuleMetadataType, SchemaMetadata} from './metadata/ng_module';
import {ViewEncapsulation} from './metadata/view';
import {Type} from './type';
import {TypeDecorator, makeDecorator, makeParamDecorator, makePropDecorator} from './util/decorators';
export {ANALYZE_FOR_ENTRY_COMPONENTS, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
@ -28,6 +25,7 @@ export {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NgModuleMetadata, NgModuleM
export {ViewEncapsulation, ViewMetadata} from './metadata/view';
/**
* Interface for the {@link DirectiveMetadata} decorator function.
*
@ -218,10 +216,11 @@ export interface AttributeMetadataFactory {
* @deprecated
*/
export interface QueryMetadataFactory {
(selector: Type|string,
(selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): ParameterDecorator;
new (selector: Type|string, {descendants, read}?: {descendants?: boolean, read?: any}):
QueryMetadata;
new (
selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): QueryMetadata;
}
/**
@ -229,9 +228,11 @@ export interface QueryMetadataFactory {
* @stable
*/
export interface ContentChildrenMetadataFactory {
(selector: Type|string, {descendants, read}?: {descendants?: boolean, read?: any}): any;
new (selector: Type|string, {descendants, read}?: {descendants?: boolean, read?: any}):
ContentChildrenMetadata;
(selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): any;
new (
selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): ContentChildrenMetadata;
}
/**
@ -239,8 +240,8 @@ export interface ContentChildrenMetadataFactory {
* @stable
*/
export interface ContentChildMetadataFactory {
(selector: Type|string, {read}?: {read?: any}): any;
new (selector: Type|string, {read}?: {read?: any}): ContentChildMetadataFactory;
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ContentChildMetadataFactory;
}
/**
@ -248,8 +249,8 @@ export interface ContentChildMetadataFactory {
* @stable
*/
export interface ViewChildrenMetadataFactory {
(selector: Type|string, {read}?: {read?: any}): any;
new (selector: Type|string, {read}?: {read?: any}): ViewChildrenMetadata;
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ViewChildrenMetadata;
}
/**
@ -257,8 +258,8 @@ export interface ViewChildrenMetadataFactory {
* @stable
*/
export interface ViewChildMetadataFactory {
(selector: Type|string, {read}?: {read?: any}): any;
new (selector: Type|string, {read}?: {read?: any}): ViewChildMetadataFactory;
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ViewChildMetadataFactory;
}

View File

@ -9,7 +9,8 @@
import {resolveForwardRef} from '../di/forward_ref';
import {DependencyMetadata} from '../di/metadata';
import {OpaqueToken} from '../di/opaque_token';
import {StringWrapper, Type, isString, stringify} from '../facade/lang';
import {StringWrapper, isString, stringify} from '../facade/lang';
import {Type} from '../type';
/**
* This token can be used to create a virtual provider that will populate the
@ -199,11 +200,10 @@ export class QueryMetadata extends DependencyMetadata {
*/
read: any;
constructor(private _selector: Type|string, {descendants = false, first = false, read = null}: {
descendants?: boolean,
first?: boolean,
read?: any
} = {}) {
constructor(
private _selector: Type<any>|string,
{descendants = false, first = false,
read = null}: {descendants?: boolean, first?: boolean, read?: any} = {}) {
super();
this.descendants = descendants;
this.first = first;
@ -258,7 +258,7 @@ export class QueryMetadata extends DependencyMetadata {
*/
export class ContentChildrenMetadata extends QueryMetadata {
constructor(
_selector: Type|string,
_selector: Type<any>|string,
{descendants = false, read = null}: {descendants?: boolean, read?: any} = {}) {
super(_selector, {descendants: descendants, read: read});
}
@ -287,7 +287,7 @@ export class ContentChildrenMetadata extends QueryMetadata {
* @stable
*/
export class ContentChildMetadata extends QueryMetadata {
constructor(_selector: Type|string, {read = null}: {read?: any} = {}) {
constructor(_selector: Type<any>|string, {read = null}: {read?: any} = {}) {
super(_selector, {descendants: true, first: true, read: read});
}
}
@ -330,8 +330,8 @@ export class ContentChildMetadata extends QueryMetadata {
*/
export class ViewQueryMetadata extends QueryMetadata {
constructor(
_selector: Type|string, {descendants = false, first = false, read = null}:
{descendants?: boolean, first?: boolean, read?: any} = {}) {
_selector: Type<any>|string, {descendants = false, first = false, read = null}:
{descendants?: boolean, first?: boolean, read?: any} = {}) {
super(_selector, {descendants: descendants, first: first, read: read});
}
@ -421,7 +421,7 @@ export class ViewQueryMetadata extends QueryMetadata {
* @stable
*/
export class ViewChildrenMetadata extends ViewQueryMetadata {
constructor(_selector: Type|string, {read = null}: {read?: any} = {}) {
constructor(_selector: Type<any>|string, {read = null}: {read?: any} = {}) {
super(_selector, {descendants: true, read: read});
}
}
@ -498,7 +498,7 @@ export class ViewChildrenMetadata extends ViewQueryMetadata {
* @stable
*/
export class ViewChildMetadata extends ViewQueryMetadata {
constructor(_selector: Type|string, {read = null}: {read?: any} = {}) {
constructor(_selector: Type<any>|string, {read = null}: {read?: any} = {}) {
super(_selector, {descendants: true, first: true, read: read});
}
}

View File

@ -9,8 +9,8 @@
import {AnimationEntryMetadata} from '../animation/metadata';
import {ChangeDetectionStrategy} from '../change_detection/constants';
import {InjectableMetadata} from '../di/metadata';
import {Type, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
import {Type} from '../type';
import {ViewEncapsulation} from './view';
/**
@ -792,11 +792,11 @@ export interface ComponentMetadataType extends DirectiveMetadataType {
styleUrls?: string[];
styles?: string[];
animations?: AnimationEntryMetadata[];
directives?: Array<Type|any[]>;
pipes?: Array<Type|any[]>;
directives?: Array<Type<any>|any[]>;
pipes?: Array<Type<any>|any[]>;
encapsulation?: ViewEncapsulation;
interpolation?: [string, string];
entryComponents?: Array<Type|any[]>;
entryComponents?: Array<Type<any>|any[]>;
}
/**
@ -1000,9 +1000,9 @@ export class ComponentMetadata extends DirectiveMetadata implements ComponentMet
*/
animations: AnimationEntryMetadata[];
directives: Array<Type|any[]>;
directives: Array<Type<any>|any[]>;
pipes: Array<Type|any[]>;
pipes: Array<Type<any>|any[]>;
/**
* Specify how the template and the styles should be encapsulated.
@ -1020,7 +1020,7 @@ export class ComponentMetadata extends DirectiveMetadata implements ComponentMet
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
* {@link ComponentFactoryResolver ComponentFactoryResolver}.
*/
entryComponents: Array<Type|any[]>;
entryComponents: Array<Type<any>|any[]>;
constructor({selector,
inputs,

View File

@ -7,7 +7,7 @@
*/
import {InjectableMetadata} from '../di/metadata';
import {Type} from '../facade/lang';
import {Type} from '../type';
/**
* A wrapper around a module that also includes the providers.
@ -15,7 +15,7 @@ import {Type} from '../facade/lang';
* @experimental
*/
export interface ModuleWithProviders {
ngModule: Type;
ngModule: Type<any>;
providers?: any[];
}
@ -42,11 +42,11 @@ export const CUSTOM_ELEMENTS_SCHEMA: SchemaMetadata = {
*/
export interface NgModuleMetadataType {
providers?: any[];
declarations?: Array<Type|any[]>;
imports?: Array<Type|ModuleWithProviders|any[]>;
exports?: Array<Type|any[]>;
entryComponents?: Array<Type|any[]>;
bootstrap?: Array<Type|any[]>;
declarations?: Array<Type<any>|any[]>;
imports?: Array<Type<any>|ModuleWithProviders|any[]>;
exports?: Array<Type<any>|any[]>;
entryComponents?: Array<Type<any>|any[]>;
bootstrap?: Array<Type<any>|any[]>;
schemas?: Array<SchemaMetadata|any[]>;
}
@ -101,7 +101,7 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
* }
* ```
*/
declarations: Array<Type|any[]>;
declarations: Array<Type<any>|any[]>;
/**
* Specifies a list of modules whose exported directives/pipes
@ -118,7 +118,7 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
* }
* ```
*/
imports: Array<Type|ModuleWithProviders|any[]>;
imports: Array<Type<any>|ModuleWithProviders|any[]>;
/**
* Specifies a list of directives/pipes/module that can be used within the template
@ -135,7 +135,7 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
* }
* ```
*/
exports: Array<Type|any[]>;
exports: Array<Type<any>|any[]>;
/**
* Defines the components that should be compiled as well when
@ -143,14 +143,14 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
* {@link ComponentFactoryResolver ComponentFactoryResolver}.
*/
entryComponents: Array<Type|any[]>;
entryComponents: Array<Type<any>|any[]>;
/**
* Defines the components that should be bootstrapped when
* this module is bootstrapped. The components listed here
* will automatically be added to `entryComponents`.
*/
bootstrap: Array<Type|any[]>;
bootstrap: Array<Type<any>|any[]>;
schemas: Array<SchemaMetadata|any[]>;

View File

@ -7,7 +7,7 @@
*/
import {AnimationEntryMetadata} from '../animation/metadata';
import {Type} from '../facade/lang';
import {Type} from '../type';
/**
@ -123,9 +123,9 @@ export class ViewMetadata {
* }
* ```
*/
directives: Array<Type|any[]>;
directives: Array<Type<any>|any[]>;
pipes: Array<Type|any[]>;
pipes: Array<Type<any>|any[]>;
/**
* Specify how the template and the styles should be encapsulated.
@ -144,8 +144,8 @@ export class ViewMetadata {
interpolation}: {
templateUrl?: string,
template?: string,
directives?: Array<Type|any[]>,
pipes?: Array<Type|any[]>,
directives?: Array<Type<any>|any[]>,
pipes?: Array<Type<any>|any[]>,
encapsulation?: ViewEncapsulation,
styles?: string[],
styleUrls?: string[],

View File

@ -6,20 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '../src/facade/lang';
import {PlatformRef, PlatformRef_, createPlatformFactory} from './application_ref';
import {Console} from './console';
import {Provider} from './di';
import {Reflector, reflector} from './reflection/reflection';
import {ReflectorReader} from './reflection/reflector_reader';
import {TestabilityRegistry} from './testability/testability';
import {Type} from './type';
function _reflector(): Reflector {
return reflector;
}
const _CORE_PLATFORM_PROVIDERS: Array<any|Type|Provider|any[]> = [
const _CORE_PLATFORM_PROVIDERS: Array<any|Type<any>|Provider|any[]> = [
PlatformRef_, {provide: PlatformRef, useExisting: PlatformRef_},
{provide: Reflector, useFactory: _reflector, deps: []},
{provide: ReflectorReader, useExisting: Reflector}, TestabilityRegistry, Console

View File

@ -6,20 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '../facade/lang';
import {Type} from '../type';
import {GetterFn, MethodFn, SetterFn} from './types';
export interface PlatformReflectionCapabilities {
isReflectionEnabled(): boolean;
factory(type: Type): Function;
interfaces(type: Type): any[];
hasLifecycleHook(type: any, lcInterface: /*Type*/ any, lcProperty: string): boolean;
parameters(type: any): any[][];
annotations(type: any): any[];
propMetadata(typeOrFunc: any): {[key: string]: any[]};
factory(type: Type<any>): Function;
interfaces(type: Type<any>): any[];
hasLifecycleHook(type: any, lcInterface: Type<any>, lcProperty: string): boolean;
parameters(type: Type<any>): any[][];
annotations(type: Type<any>): any[];
propMetadata(typeOrFunc: Type<any>): {[key: string]: any[]};
getter(name: string): GetterFn;
setter(name: string): SetterFn;
method(name: string): MethodFn;
importUri(type: any): string;
importUri(type: Type<any>): string;
}

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '../facade/exceptions';
import {ConcreteType, Type, global, isFunction, isPresent, stringify} from '../facade/lang';
import {global, isFunction, isPresent, stringify} from '../facade/lang';
import {Type} from '../type';
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
import {GetterFn, MethodFn, SetterFn} from './types';
@ -15,92 +15,17 @@ import {GetterFn, MethodFn, SetterFn} from './types';
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
private _reflect: any;
constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; }
constructor(reflect?: any) { this._reflect = reflect || global.Reflect; }
isReflectionEnabled(): boolean { return true; }
factory(t: ConcreteType<any>): Function {
switch (t.length) {
case 0:
return () => new t();
case 1:
return (a1: any) => new t(a1);
case 2:
return (a1: any, a2: any) => new t(a1, a2);
case 3:
return (a1: any, a2: any, a3: any) => new t(a1, a2, a3);
case 4:
return (a1: any, a2: any, a3: any, a4: any) => new t(a1, a2, a3, a4);
case 5:
return (a1: any, a2: any, a3: any, a4: any, a5: any) => new t(a1, a2, a3, a4, a5);
case 6:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any) =>
new t(a1, a2, a3, a4, a5, a6);
case 7:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any) =>
new t(a1, a2, a3, a4, a5, a6, a7);
case 8:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8);
case 9:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9);
case 10:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any) => new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
case 11:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any) => new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
case 12:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
case 13:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
case 14:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
case 15:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
case 16:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any, a16: any) =>
new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16);
case 17:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any, a16: any, a17: any) =>
new t(
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17);
case 18:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any, a16: any, a17: any,
a18: any) =>
new t(
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17,
a18);
case 19:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any, a16: any, a17: any,
a18: any, a19: any) =>
new t(
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17,
a18, a19);
case 20:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any, a9: any,
a10: any, a11: any, a12: any, a13: any, a14: any, a15: any, a16: any, a17: any,
a18: any, a19: any, a20: any) =>
new t(
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17,
a18, a19, a20);
factory(t: Type<any>): Function {
var prototype = t.prototype;
return function(...args: any[]) {
var instance = Object.create(prototype);
t.apply(instance, args);
return instance;
};
throw new Error(
`Cannot create a factory for '${stringify(t)}' because its constructor has more than 20 arguments`);
}
/** @internal */
@ -132,7 +57,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
return result;
}
parameters(typeOrFunc: Type): any[][] {
parameters(typeOrFunc: Type<any>): any[][] {
// Prefer the direct API.
if (isPresent((<any>typeOrFunc).parameters)) {
return (<any>typeOrFunc).parameters;
@ -163,7 +88,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
return parameters;
}
annotations(typeOrFunc: Type): any[] {
annotations(typeOrFunc: Type<any>): any[] {
// Prefer the direct API.
if (isPresent((<any>typeOrFunc).annotations)) {
var annotations = (<any>typeOrFunc).annotations;
@ -217,9 +142,9 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
// Note: JavaScript does not support to query for interfaces during runtime.
// However, we can't throw here as the reflector will always call this method
// when asked for a lifecycle interface as this is what we check in Dart.
interfaces(type: Type): any[] { return []; }
interfaces(type: Type<any>): any[] { return []; }
hasLifecycleHook(type: any, lcInterface: Type, lcProperty: string): boolean {
hasLifecycleHook(type: any, lcInterface: Type<any>, lcProperty: string): boolean {
if (!(type instanceof Type)) return false;
var proto = (<any>type).prototype;

View File

@ -8,8 +8,8 @@
import {Map, MapWrapper, Set, SetWrapper, StringMapWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {Type, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
import {Type} from '../type';
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
import {ReflectorReader} from './reflector_reader';
import {GetterFn, MethodFn, SetterFn} from './types';
@ -77,7 +77,7 @@ export class Reflector extends ReflectorReader {
this._injectableInfo.set(func, funcInfo);
}
registerType(type: Type, typeInfo: ReflectionInfo): void {
registerType(type: Type<any>, typeInfo: ReflectionInfo): void {
this._injectableInfo.set(type, typeInfo);
}
@ -87,7 +87,7 @@ export class Reflector extends ReflectorReader {
registerMethods(methods: {[key: string]: MethodFn}): void { _mergeMaps(this._methods, methods); }
factory(type: Type): Function {
factory(type: Type<any>): Function {
if (this._containsReflectionInfo(type)) {
var res = this._getReflectionInfo(type).factory;
return isPresent(res) ? res : null;
@ -96,7 +96,7 @@ export class Reflector extends ReflectorReader {
}
}
parameters(typeOrFunc: /*Type*/ any): any[][] {
parameters(typeOrFunc: Type<any>): any[][] {
if (this._injectableInfo.has(typeOrFunc)) {
var res = this._getReflectionInfo(typeOrFunc).parameters;
return isPresent(res) ? res : [];
@ -105,7 +105,7 @@ export class Reflector extends ReflectorReader {
}
}
annotations(typeOrFunc: /*Type*/ any): any[] {
annotations(typeOrFunc: Type<any>): any[] {
if (this._injectableInfo.has(typeOrFunc)) {
var res = this._getReflectionInfo(typeOrFunc).annotations;
return isPresent(res) ? res : [];
@ -114,7 +114,7 @@ export class Reflector extends ReflectorReader {
}
}
propMetadata(typeOrFunc: /*Type*/ any): {[key: string]: any[]} {
propMetadata(typeOrFunc: Type<any>): {[key: string]: any[]} {
if (this._injectableInfo.has(typeOrFunc)) {
var res = this._getReflectionInfo(typeOrFunc).propMetadata;
return isPresent(res) ? res : {};
@ -123,7 +123,7 @@ export class Reflector extends ReflectorReader {
}
}
interfaces(type: /*Type*/ any): any[] {
interfaces(type: Type<any>): any[] {
if (this._injectableInfo.has(type)) {
var res = this._getReflectionInfo(type).interfaces;
return isPresent(res) ? res : [];
@ -132,7 +132,7 @@ export class Reflector extends ReflectorReader {
}
}
hasLifecycleHook(type: any, lcInterface: Type, lcProperty: string): boolean {
hasLifecycleHook(type: any, lcInterface: Type<any>, lcProperty: string): boolean {
var interfaces = this.interfaces(type);
if (interfaces.indexOf(lcInterface) !== -1) {
return true;

View File

@ -0,0 +1,20 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* Runtime representation a type that a Component or other object is instances of.
*
* An example of a `Type` is `MyCustomComponent` class, which in JavaScript is be represented by
* the `MyCustomComponent` constructor function.
*
* @stable
*/
export var Type = Function;
export interface Type<T> extends Function { new (...args: any[]): T; }

View File

@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConcreteType, Type, global, isFunction, stringify} from '../facade/lang';
import {global, isFunction, stringify} from '../facade/lang';
import {Type} from '../type';
var _nextClassId = 0;
@ -19,7 +20,7 @@ export interface ClassDefinition {
/**
* Optional argument for specifying the superclass.
*/
extends?: Type;
extends?: Type<any>;
/**
* Required constructor function for a class.
@ -36,7 +37,7 @@ export interface ClassDefinition {
* Other methods on the class. Note that values should have type 'Function' but TS requires
* all properties to have a narrower type than the index signature.
*/
[x: string]: Type|Function|any[];
[x: string]: Type<any>|Function|any[];
}
/**
@ -66,7 +67,7 @@ export interface TypeDecorator {
/**
* Invoke as ES7 decorator.
*/
<T extends Type>(type: T): T;
<T extends Type<any>>(type: T): T;
// Make TypeDecorator assignable to built-in ParameterDecorator type.
// ParameterDecorator is declared in lib.d.ts as a `declare type`
@ -84,7 +85,7 @@ export interface TypeDecorator {
/**
* Generate a class from the definition and annotate it with {@link TypeDecorator#annotations}.
*/
Class(obj: ClassDefinition): ConcreteType<any>;
Class(obj: ClassDefinition): Type<any>;
}
function extractAnnotation(annotation: any): any {
@ -219,7 +220,7 @@ function applyParams(fnOrArray: (Function | any[]), key: string): Function {
* ```
* @stable
*/
export function Class(clsDef: ClassDefinition): ConcreteType<any> {
export function Class(clsDef: ClassDefinition): Type<any> {
const constructor = applyParams(
clsDef.hasOwnProperty('constructor') ? clsDef.constructor : undefined, 'constructor');
let proto = constructor.prototype;
@ -246,7 +247,7 @@ export function Class(clsDef: ClassDefinition): ConcreteType<any> {
(constructor as any)['overriddenName'] = `class${_nextClassId++}`;
}
return <ConcreteType<any>>constructor;
return <Type<any>>constructor;
}
var Reflect = global.Reflect;
@ -268,7 +269,7 @@ export function makeDecorator(annotationCls: any, chainFn: (fn: Function) => voi
const chainAnnotation =
isFunction(this) && this.annotations instanceof Array ? this.annotations : [];
chainAnnotation.push(annotationInstance);
const TypeDecorator: TypeDecorator = <TypeDecorator>function TypeDecorator(cls: Type) {
const TypeDecorator: TypeDecorator = <TypeDecorator>function TypeDecorator(cls: Type<any>) {
const annotations = Reflect.getOwnMetadata('annotations', cls) || [];
annotations.push(annotationInstance);
Reflect.defineMetadata('annotations', annotations, cls);