diff --git a/modules/angular2/src/di/annotations_impl.ts b/modules/angular2/src/di/annotations_impl.ts index 566e94a27f..42ce53ff05 100644 --- a/modules/angular2/src/di/annotations_impl.ts +++ b/modules/angular2/src/di/annotations_impl.ts @@ -15,7 +15,7 @@ import {CONST, stringify} from "angular2/src/facade/lang"; @CONST() export class Inject { constructor(public token) {} - toString() { return `@Inject(${stringify(this.token)})`; } + toString(): string { return `@Inject(${stringify(this.token)})`; } } /** @@ -34,7 +34,7 @@ export class Inject { @CONST() export class InjectPromise { constructor(public token) {} - toString() { return `@InjectPromise(${stringify(this.token)})`; } + toString(): string { return `@InjectPromise(${stringify(this.token)})`; } } /** @@ -53,7 +53,7 @@ export class InjectPromise { @CONST() export class InjectLazy { constructor(public token) {} - toString() { return `@InjectLazy(${stringify(this.token)})`; } + toString(): string { return `@InjectLazy(${stringify(this.token)})`; } } /** @@ -72,7 +72,7 @@ export class InjectLazy { */ @CONST() export class Optional { - toString() { return `@Optional()`; } + toString(): string { return `@Optional()`; } } /** diff --git a/modules/angular2/src/di/binding.ts b/modules/angular2/src/di/binding.ts index dd9a2e5fd0..705e164d41 100644 --- a/modules/angular2/src/di/binding.ts +++ b/modules/angular2/src/di/binding.ts @@ -3,6 +3,7 @@ import { isBlank, isPresent, CONST, + CONST_EXPR, BaseException, stringify, isArray @@ -30,7 +31,7 @@ export class Dependency { static fromKey(key: Key) { return new Dependency(key, false, false, false, []); } } -var _EMPTY_LIST = []; // TODO: make const when supported +const _EMPTY_LIST = CONST_EXPR([]); /** * Describes how the {@link Injector} should instantiate a given token. diff --git a/modules/angular2/src/di/exceptions.ts b/modules/angular2/src/di/exceptions.ts index 5b2098eb3e..28e701451b 100644 --- a/modules/angular2/src/di/exceptions.ts +++ b/modules/angular2/src/di/exceptions.ts @@ -140,6 +140,7 @@ export class CyclicDependencyError extends AbstractBindingError { export class InstantiationError extends AbstractBindingError { cause; causeKey; + // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(cause, key) { super(key, function(keys: List) { diff --git a/modules/angular2/src/di/forward_ref.ts b/modules/angular2/src/di/forward_ref.ts index a80d4c1652..c3083f1b2d 100644 --- a/modules/angular2/src/di/forward_ref.ts +++ b/modules/angular2/src/di/forward_ref.ts @@ -1,4 +1,4 @@ -import {Type, stringify} from 'angular2/src/facade/lang'; +import {Type, stringify, isFunction} from 'angular2/src/facade/lang'; export interface ForwardRefFn { (): any; } @@ -42,7 +42,7 @@ export function forwardRef(forwardRefFn: ForwardRefFn): Type { * @exportedAs angular2/di */ export function resolveForwardRef(type: any): any { - if (typeof type == 'function' && type.hasOwnProperty('__forward_ref__') && + if (isFunction(type) && type.hasOwnProperty('__forward_ref__') && type.__forward_ref__ === forwardRef) { return (type)(); } else { diff --git a/modules/angular2/src/di/key.ts b/modules/angular2/src/di/key.ts index c1cd355eba..6b2627d09f 100644 --- a/modules/angular2/src/di/key.ts +++ b/modules/angular2/src/di/key.ts @@ -5,8 +5,6 @@ import {resolveForwardRef} from './forward_ref'; export {TypeLiteral} from './type_literal'; -// TODO: uncoment `int` once https://github.com/angular/angular/issues/1414 is fixed - /** * A unique object used for retrieving items from the {@link Injector}. * @@ -20,21 +18,16 @@ export {TypeLiteral} from './type_literal'; * @exportedAs angular2/di */ export class Key { - token: Object; - id: number; - /** * @private */ - constructor(token: Object, id: number) { + constructor(public token: Object, public id: number) { if (isBlank(token)) { throw new BaseException('Token must be defined!'); } - this.token = token; - this.id = id; } - get displayName() { return stringify(this.token); } + get displayName(): string { return stringify(this.token); } /** * Retrieves a `Key` for a token. @@ -51,8 +44,7 @@ export class Key { * @private */ export class KeyRegistry { - _allKeys: Map; - constructor() { this._allKeys = MapWrapper.create(); } + private _allKeys: Map = MapWrapper.create(); get(token: Object): Key { if (token instanceof Key) return token; @@ -73,7 +65,7 @@ export class KeyRegistry { return newKey; } - get numberOfKeys() /* :int */ { return MapWrapper.size(this._allKeys); } + get numberOfKeys(): number { return MapWrapper.size(this._allKeys); } } var _globalKeyRegistry = new KeyRegistry();