chore: add more type annotations

This commit is contained in:
Kevin Moore
2015-04-19 14:47:02 -07:00
parent e23004df52
commit f7f06c5ad4
17 changed files with 80 additions and 81 deletions

View File

@ -1,7 +1,7 @@
import {ListWrapper, List} from 'angular2/src/facade/collection';
import {stringify} from 'angular2/src/facade/lang';
function findFirstClosedCycle(keys:List) {
function findFirstClosedCycle(keys:List):List {
var res = [];
for(var i = 0; i < keys.length; ++i) {
if (ListWrapper.contains(res, keys[i])) {
@ -14,7 +14,7 @@ function findFirstClosedCycle(keys:List) {
return res;
}
function constructResolvingPath(keys:List) {
function constructResolvingPath(keys:List):string {
if (keys.length > 1) {
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
@ -43,12 +43,12 @@ export class AbstractBindingError extends Error {
}
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
addKey(key) {
addKey(key):void {
ListWrapper.push(this.keys, key);
this.message = this.constructResolvingMessage(this.keys);
}
toString() {
toString():string {
return this.message;
}
}
@ -166,7 +166,7 @@ export class InvalidBindingError extends Error {
this.message = `Invalid binding ${binding}`;
}
toString() {
toString():string {
return this.message;
}
}
@ -187,7 +187,7 @@ export class NoAnnotationError extends Error {
` Make sure they all have valid type or annotations.`;
}
toString() {
toString():string {
return this.message;
}
}

View File

@ -97,7 +97,7 @@ export class Injector {
* bindings.
* @param `defaultBindings` Setting to true will auto-create bindings.
*/
static resolveAndCreate(bindings:List/*<ResolvedBinding|Binding|Type|List>*/, {defaultBindings=false}={}) {
static resolveAndCreate(bindings:List/*<ResolvedBinding|Binding|Type|List>*/, {defaultBindings=false}={}): Injector {
return new Injector(Injector.resolve(bindings), null, defaultBindings);
}
@ -108,7 +108,7 @@ export class Injector {
* @param `bindings` A sparse list of {@link ResolvedBinding}s. See `resolve` for the {@link Injector}.
* @param `defaultBindings` Setting to true will auto-create bindings.
*/
static fromResolvedBindings(bindings:List<ResolvedBinding>, {defaultBindings=false}={}) {
static fromResolvedBindings(bindings:List<ResolvedBinding>, {defaultBindings=false}={}): Injector {
return new Injector(bindings, null, defaultBindings);
}
@ -133,7 +133,6 @@ export class Injector {
* @returns an instance represented by the token. Throws if not found.
*/
get(token) {
return this._getByKey(Key.get(token), false, false, false);
}
@ -227,7 +226,7 @@ export class Injector {
return ListWrapper.get(this._instances, key.id);
}
_setInstance(key:Key, obj) {
_setInstance(key:Key, obj):void {
ListWrapper.set(this._instances, key.id, obj);
}
@ -243,11 +242,11 @@ export class Injector {
}
}
_markAsConstructing(key:Key) {
_markAsConstructing(key:Key):void {
this._setInstance(key, _constructing);
}
_clear(key:Key) {
_clear(key:Key):void {
this._setInstance(key, null);
}
}
@ -325,7 +324,7 @@ class _AsyncInjectorStrategy {
}
}
instantiate(key:Key) {
instantiate(key:Key) /* Promise?? */ {
var binding = this.injector._getBinding(key);
if (isBlank(binding)) return _notFound;
@ -395,7 +394,7 @@ function _createListOfBindings(flattenedBindings):List {
return bindings;
}
function _flattenBindings(bindings:List, res:Map) {
function _flattenBindings(bindings:List, res:Map):Map {
ListWrapper.forEach(bindings, function (b) {
if (b instanceof ResolvedBinding) {
MapWrapper.set(res, b.key.id, b);

View File

@ -10,7 +10,7 @@ export class OpaqueToken {
this._desc = `Token(${desc})`;
}
toString() {
toString():string {
return this._desc;
}
}