fix(build): add missing return types now enforced by linter

This commit is contained in:
Alex Eagle
2015-06-26 11:10:52 -07:00
parent bc585f2724
commit 44891996b5
61 changed files with 467 additions and 400 deletions

View File

@ -7,6 +7,12 @@ import * as Rx from 'rx';
export var Promise = (<any>global).Promise;
export interface PromiseCompleter<R> {
promise: Promise<R>;
resolve: (value?: R | Thenable<R>) => void;
reject: (error?: any, stackTrace?: string) => void;
}
export class PromiseWrapper {
static resolve(obj): Promise<any> { return Promise.resolve(obj); }
@ -38,7 +44,7 @@ export class PromiseWrapper {
});
}
static completer() {
static completer(): PromiseCompleter<any> {
var resolve;
var reject;
@ -103,7 +109,7 @@ export class EventEmitter extends Observable {
}
}
observer(generator) {
observer(generator): Rx.IDisposable {
return this._subject.observeOn(this._immediateScheduler)
.subscribe((value) => { setTimeout(() => generator.next(value)); },
(error) => generator.throw ? generator.throw(error) : null,

View File

@ -90,6 +90,8 @@ class StringMapWrapper {
}
}
typedef bool Predicate<T>(T item);
class ListWrapper {
static List clone(Iterable l) => new List.from(l);
static List createFixedSize(int size) => new List(size);

View File

@ -65,10 +65,10 @@ export class MapWrapper {
}
static createFromPairs(pairs: List<any>): Map<any, any> { return createMapFromPairs(pairs); }
static forEach<K, V>(m: Map<K, V>, fn: /*(V, K) => void*/ Function) { m.forEach(<any>fn); }
static size(m: Map<any, any>) { return m.size; }
static size(m: Map<any, any>): number { return m.size; }
static delete<K>(m: Map<K, any>, k: K) { m.delete(k); }
static clearValues(m: Map<any, any>) { _clearValues(m); }
static iterable(m) { return m; }
static iterable<T>(m: T): T { return m; }
static keys<K>(m: Map<K, any>): List<K> { return (<any>Array).from(m.keys()); }
static values<V>(m: Map<any, V>): List<V> { return (<any>Array).from(m.values()); }
}
@ -83,13 +83,15 @@ export class StringMapWrapper {
// http://jsperf.com/ng2-object-create-null
return {};
}
static contains(map: StringMap<string, any>, key: string) { return map.hasOwnProperty(key); }
static contains(map: StringMap<string, any>, key: string): boolean {
return map.hasOwnProperty(key);
}
static get<V>(map: StringMap<string, V>, key: string): V {
return map.hasOwnProperty(key) ? map[key] : undefined;
}
static set<V>(map: StringMap<string, V>, key: string, value: V) { map[key] = value; }
static keys(map: StringMap<string, any>): List<string> { return Object.keys(map); }
static isEmpty(map: StringMap<string, any>) {
static isEmpty(map: StringMap<string, any>): boolean {
for (var prop in map) {
return false;
}
@ -139,57 +141,59 @@ export class StringMapWrapper {
}
}
export interface Predicate<T> { (value: T, index?: number, array?: T[]): boolean; }
export class ListWrapper {
// JS has no way to express a staticly fixed size list, but dart does so we
// keep both methods.
static createFixedSize(size): List<any> { return new List(size); }
static createGrowableSize(size): List<any> { return new List(size); }
static get(m, k) { return m[k]; }
static get(m, k): any { return m[k]; }
static set(m, k, v) { m[k] = v; }
static clone(array: List<any>) { return array.slice(0); }
static map(array, fn) { return array.map(fn); }
static clone<T>(array: List<T>): T[] { return array.slice(0); }
static map(array, fn): any { return array.map(fn); }
static forEach(array: List<any>, fn: Function) {
for (var i = 0; i < array.length; i++) {
fn(array[i]);
}
}
static first(array) {
static first<T>(array: List<T>): T {
if (!array) return null;
return array[0];
}
static last(array) {
static last<T>(array: List<T>): T {
if (!array || array.length == 0) return null;
return array[array.length - 1];
}
static find(list: List<any>, pred: Function) {
static find<T>(list: List<T>, pred: Predicate<T>): T {
for (var i = 0; i < list.length; ++i) {
if (pred(list[i])) return list[i];
}
return null;
}
static indexOf(array: List<any>, value, startIndex = 0) {
static indexOf(array: List<any>, value, startIndex = 0): number {
return array.indexOf(value, startIndex);
}
static reduce<T, E>(list: List<T>,
fn: (accumValue: E, currentValue: T, currentIndex: number, array: T[]) => E,
init: E) {
init: E): E {
return list.reduce(fn, init);
}
static filter(array, pred: Function) { return array.filter(pred); }
static any(list: List<any>, pred: Function) {
static filter<T>(array: List<T>, pred: Predicate<T>): T[] { return array.filter(pred); }
static any(list: List<any>, pred: Function): boolean {
for (var i = 0; i < list.length; ++i) {
if (pred(list[i])) return true;
}
return false;
}
static contains(list: List<any>, el) { return list.indexOf(el) !== -1; }
static reversed(array) {
static contains(list: List<any>, el): boolean { return list.indexOf(el) !== -1; }
static reversed<T>(array: List<T>): T[] {
var a = ListWrapper.clone(array);
return a.reverse();
}
static concat(a, b) { return a.concat(b); }
static concat(a, b): List<any> { return a.concat(b); }
static insert(list, index: int, value) { list.splice(index, 0, value); }
static removeAt(list, index: int) {
static removeAt<T>(list: List<T>, index: int): T {
var res = list[index];
list.splice(index, 1);
return res;
@ -210,8 +214,8 @@ export class ListWrapper {
return false;
}
static clear(list) { list.splice(0, list.length); }
static join(list, s) { return list.join(s); }
static isEmpty(list) { return list.length == 0; }
static join(list, s: string): string { return list.join(s); }
static isEmpty(list): boolean { return list.length == 0; }
static fill(list: List<any>, value, start: int = 0, end: int = null) {
list.fill(value, start, end === null ? undefined : end);
}

View File

@ -37,18 +37,18 @@ export function CONST_EXPR<T>(expr: T): T {
return expr;
}
export function CONST() {
export function CONST():<T>(target: T) => T {
return (target) => target;
}
export function ABSTRACT() {
export function ABSTRACT():<T>(target: T) => T {
return (t) => t;
}
// Note: This is only a marker annotation needed for ts2dart.
// This is written so that is can be used as a Traceur annotation
// or a Typescript decorator.
export function IMPLEMENTS(_) {
export function IMPLEMENTS(_):<T>(target: T) => T {
return (t) => t;
}
@ -152,7 +152,7 @@ export class NumberParseError extends BaseException {
constructor(public message: string) { super(); }
toString() { return this.message; }
toString(): string { return this.message; }
}
@ -211,7 +211,11 @@ export class RegExpWrapper {
return regExp.exec(input);
}
static test(regExp: RegExp, input: string): boolean { return regExp.test(input); }
static matcher(regExp, input) {
static matcher(regExp, input): {
re: RegExp;
input: string
}
{
// Reset regex state for the case
// someone did not loop over all matches
// last time.
@ -221,11 +225,11 @@ export class RegExpWrapper {
}
export class RegExpMatcherWrapper {
static next(matcher) { return matcher.re.exec(matcher.input); }
static next(matcher): string { return matcher.re.exec(matcher.input); }
}
export class FunctionWrapper {
static apply(fn: Function, posArgs) { return fn.apply(null, posArgs); }
static apply(fn: Function, posArgs): any { return fn.apply(null, posArgs); }
}
// JS has NaN !== NaN
@ -235,11 +239,11 @@ export function looseIdentical(a, b): boolean {
// JS considers NaN is the same as NaN for map Key (while NaN !== NaN otherwise)
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
export function getMapKey(value) {
export function getMapKey(value): any {
return value;
}
export function normalizeBlank(obj) {
export function normalizeBlank(obj): any {
return isBlank(obj) ? null : obj;
}
@ -261,7 +265,7 @@ export function print(obj) {
// Can't be all uppercase as our transpiler would think it is a special directive...
export class Json {
static parse(s: string) { return _global.JSON.parse(s); }
static parse(s: string): Object { return _global.JSON.parse(s); }
static stringify(data): string {
// Dart doesn't take 3 arguments
return _global.JSON.stringify(data, null, 2);
@ -269,8 +273,8 @@ export class Json {
}
export class DateWrapper {
static fromMillis(ms) { return new Date(ms); }
static toMillis(date: Date) { return date.getTime(); }
static now() { return new Date(); }
static toJson(date) { return date.toJSON(); }
static fromMillis(ms): Date { return new Date(ms); }
static toMillis(date: Date): number { return date.getTime(); }
static now(): Date { return new Date(); }
static toJson(date): string { return date.toJSON(); }
}