From 2c2c0ac7819f985a88f2fc74fb940df516f579ff Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Wed, 20 Jul 2016 19:27:08 -0400 Subject: [PATCH] Enabled noImplicitAny --- lib/generators.ts | 24 ++++---- lib/linq.ts | 148 +++++++++++++++++++++++----------------------- lib/utilities.ts | 12 ++-- tsconfig.json | 2 +- 4 files changed, 94 insertions(+), 92 deletions(-) diff --git a/lib/generators.ts b/lib/generators.ts index 321e7d3..ff2c1a4 100644 --- a/lib/generators.ts +++ b/lib/generators.ts @@ -24,7 +24,7 @@ export function* Reverse(target: Array) { } -export function* Select(target: Iterable, transform: (T, number) => V) { +export function* Select(target: Iterable, transform: (x: T, i: number) => V) { let index = 0; for (let value of target) { yield transform(value, index++); @@ -44,7 +44,7 @@ export function* DefaultIfEmpty(target: Iterable, defaultValue: T) { } -export function* Distinct(target: Iterable, keySelector: (T) => V) { +export function* Distinct(target: Iterable, keySelector: (x: T) => V) { let set: Set = new Set(); for (let value of target) { let key: V = keySelector(value); @@ -65,7 +65,7 @@ export function* DistinctFast(target: Iterable) { } -export function* Where(target: Iterable, predicate: (T, number) => Boolean) { +export function* Where(target: Iterable, predicate: (x: T, i: number) => Boolean) { let index = 0; for (let value of target) { if (!predicate(value, index++)) continue; @@ -83,7 +83,7 @@ export function* Skip(target: Iterable, skip: number) { } -export function* SkipWhile(target: Iterable, predicate: (T, number) => Boolean) { +export function* SkipWhile(target: Iterable, predicate: (x: T, i: number) => Boolean) { let index = 0, skipped = false; for (let value of target) { if (!skipped && !(skipped = !predicate(value, index++))) continue; @@ -92,7 +92,7 @@ export function* SkipWhile(target: Iterable, predicate: (T, number) => Boo } -export function* TakeWhile(target: Iterable, predicate: (T, number) => Boolean) { +export function* TakeWhile(target: Iterable, predicate: (x: T, i: number) => Boolean) { let index = 0; for (let value of target) { if (!predicate(value, index++)) return; @@ -101,7 +101,7 @@ export function* TakeWhile(target: Iterable, predicate: (T, number) => Boo } -export function* Intersect(target: Iterable, exceptions: Set | Set, condition: boolean, keySelect?: (T) => K) { +export function* Intersect(target: Iterable, exceptions: Set | Set, condition: boolean, keySelect?: (x: T) => K) { if (keySelect) { for (let value of target) { if (condition == (exceptions as Set).has(keySelect(value))) continue; @@ -132,7 +132,7 @@ export function* Range(value: any, count: number) { } -export function* Union(first: Iterable, second: Iterable, keySelector: (T) => K) { +export function* Union(first: Iterable, second: Iterable, keySelector: (x: T) => K) { let set = new Set(); for (let value of first) { let key = keySelector(value) @@ -164,7 +164,7 @@ export function* UnionFast(first: Iterable, second: Iterable) { } -export function* Join(target: Iterable, oKeySelect: (T) => K, transform: (T, any) => R, map: Map>) { +export function* Join(target: Iterable, oKeySelect: (x: T) => K, transform: (x: T, a: any) => R, map: Map>) { for (let value of target) { let key = oKeySelect(value); let innerSet = map.get(key); @@ -176,7 +176,7 @@ export function* Join(target: Iterable, oKeySelect: (T) => K, tra } -export function* GroupJoin(target: Iterable, oKeySelect: (T) => K, transform: (a: T, b: Iterable) => R, map: Map>) { +export function* GroupJoin(target: Iterable, oKeySelect: (x: T) => K, transform: (a: T, b: Iterable) => R, map: Map>) { for (let value of target) { let key = oKeySelect(value); let innerSet = map.get(key); @@ -193,7 +193,7 @@ export function* GroupBy(map: Map>, resultSelect: (a: K, b: } -export function* SelectMany(target: Iterable, selector: (T, number) => Iterable, transform: (T, V) => R) { +export function* SelectMany(target: Iterable, selector: (x: T, i: number) => Iterable, transform: (x: T, y: V) => R) { let index = 0; for (let item of target) { for (let collectionItem of selector(item, index++)) { @@ -210,10 +210,10 @@ export function* SelectManyFast(target: Iterable>) { } -export function* Zip(first: Iterable, second: Iterable, transform: (T, V) => Z, _index = 0) { +export function* Zip(first: Iterable, second: Iterable, transform: (x: T, a: V) => Z, _index = 0) { let iteratorOne = first[Symbol.iterator](); let iteratorTwo = second[Symbol.iterator](); - let retOne, retTwo; + let retOne: IteratorResult, retTwo: IteratorResult; while (!(retOne = iteratorOne.next()).done && !(retTwo = iteratorTwo.next()).done) { yield transform(retOne.value, retTwo.value) diff --git a/lib/linq.ts b/lib/linq.ts index 26e78f7..031c6d4 100644 --- a/lib/linq.ts +++ b/lib/linq.ts @@ -103,51 +103,51 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { this._factoryArg = arg; // JavaScript naming convention - this['aggregate'] = this.Aggregate; - this['all'] = this.All; - this['any'] = this.Any; - this['average'] = this.Average; - this['contains'] = this.Contains; - this['count'] = this.Count; - this['max'] = this.Max; - this['min'] = this.Min; - this['elementAt'] = this.ElementAt; - this['elementAtOrDefault'] = this.ElementAtOrDefault; - this['first'] = this.First; - this['firstOrDefault'] = this.FirstOrDefault; - this['last'] = this.Last; - this['lastOrDefault'] = this.LastOrDefault; - this['sequenceEqual'] = this.SequenceEqual; - this['single'] = this.Single; - this['singleOrDefault'] = this.SingleOrDefault; - this['sum'] = this.Sum; - this['toArray'] = this.ToArray; - this['toMap'] = this.ToMap; - this['toDictionary'] = this.ToDictionary; - this['defaultIfEmpty'] = this.DefaultIfEmpty; - this['concat'] = this.Concat; - this['distinct'] = this.Distinct; - this['except'] = this.Except; - this['groupBy'] = this.GroupBy; - this['groupJoin'] = this.GroupJoin; - this['intersect'] = this.Intersect; - this['join'] = this.Join; - this['orderBy'] = this.OrderBy; - this['orderByDescend'] = this.OrderByDescending; - this['thenBy'] = this.ThenBy; - this['thenByDescendi'] = this.ThenByDescending; - this['range'] = this.Range; - this['repeat'] = this.Repeat; - this['reverse'] = this.Reverse; - this['select'] = this.Select; - this['selectMany'] = this.SelectMany; - this['skip'] = this.Skip; - this['skipWhile'] = this.SkipWhile; - this['take'] = this.Take; - this['takeWhile'] = this.TakeWhile; - this['union'] = this.Union; - this['where'] = this.Where; - this['zip'] = this.Zip; + (this as any)['aggregate'] = this.Aggregate; + (this as any)['all'] = this.All; + (this as any)['any'] = this.Any; + (this as any)['average'] = this.Average; + (this as any)['contains'] = this.Contains; + (this as any)['count'] = this.Count; + (this as any)['max'] = this.Max; + (this as any)['min'] = this.Min; + (this as any)['elementAt'] = this.ElementAt; + (this as any)['elementAtOrDefault'] = this.ElementAtOrDefault; + (this as any)['first'] = this.First; + (this as any)['firstOrDefault'] = this.FirstOrDefault; + (this as any)['last'] = this.Last; + (this as any)['lastOrDefault'] = this.LastOrDefault; + (this as any)['sequenceEqual'] = this.SequenceEqual; + (this as any)['single'] = this.Single; + (this as any)['singleOrDefault'] = this.SingleOrDefault; + (this as any)['sum'] = this.Sum; + (this as any)['toArray'] = this.ToArray; + (this as any)['toMap'] = this.ToMap; + (this as any)['toDictionary'] = this.ToDictionary; + (this as any)['defaultIfEmpty'] = this.DefaultIfEmpty; + (this as any)['concat'] = this.Concat; + (this as any)['distinct'] = this.Distinct; + (this as any)['except'] = this.Except; + (this as any)['groupBy'] = this.GroupBy; + (this as any)['groupJoin'] = this.GroupJoin; + (this as any)['intersect'] = this.Intersect; + (this as any)['join'] = this.Join; + (this as any)['orderBy'] = this.OrderBy; + (this as any)['orderByDescend'] = this.OrderByDescending; + (this as any)['thenBy'] = this.ThenBy; + (this as any)['thenByDescendi'] = this.ThenByDescending; + (this as any)['range'] = this.Range; + (this as any)['repeat'] = this.Repeat; + (this as any)['reverse'] = this.Reverse; + (this as any)['select'] = this.Select; + (this as any)['selectMany'] = this.SelectMany; + (this as any)['skip'] = this.Skip; + (this as any)['skipWhile'] = this.SkipWhile; + (this as any)['take'] = this.Take; + (this as any)['takeWhile'] = this.TakeWhile; + (this as any)['union'] = this.Union; + (this as any)['where'] = this.Where; + (this as any)['zip'] = this.Zip; } /////////////////////////////////////////////////////////////////////////// @@ -175,11 +175,13 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Aggregate(seed: A, func: (aggr: A, x: T) => A = Constant.selfFn, resultSelector: (aggr: A) => B = Constant.selfFn): - B { - let zero, method, selector; + B { + let zero: A; + let method: (aggr: A, x: T) => A; + let selector: (aggr: A) => B; if (Constant.CONST_FUNCTION === typeof seed) { - method = seed; - selector = func; + method = seed as any; + selector = func as any; } else { zero = seed; method = func; @@ -221,7 +223,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Average(func: (x: T) => number = Constant.selfFn): number { - let result, sum = 0, count = 0; + let sum = 0, count = 0; for (let value of this) { sum += func(value); count++; @@ -250,8 +252,8 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { count++; } } - } else if (undefined != this._target[Constant.CONST_LENGTH]) { - count = this._target[Constant.CONST_LENGTH]; + } else if (undefined != (this._target as any)[Constant.CONST_LENGTH]) { + count = (this._target as any)[Constant.CONST_LENGTH]; } else { for (let value of this) { count++; @@ -262,7 +264,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Max(transform: (x: T) => number = Constant.selfFn): number { - let value, max, hasValue = false; + let value: number, max: number, hasValue = false; for (let item of this) { value = transform(item); if (hasValue) { @@ -279,7 +281,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Min(transform: (x: T) => number = Constant.selfFn): number { - let value, min, hasValue = false; + let value: number, min: number, hasValue = false; for (let item of this) { value = transform(item); if (hasValue) { @@ -297,10 +299,10 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public ElementAt(index: number): T { if (Array.isArray(this._target)) { - if (0 > index || this._target[Constant.CONST_LENGTH] <= index) { + if (0 > index || (this._target as any)[Constant.CONST_LENGTH] <= index) { throw Constant.CONST_OUTOFRANGE; } - return this._target[index]; + return (this._target as any)[index]; } let count = 0; for (let value of this) { @@ -315,16 +317,16 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public ElementAtOrDefault(index: number): T { if (Array.isArray(this._target)) { - let length = this._target[Constant.CONST_LENGTH]; + let length = (this._target as any)[Constant.CONST_LENGTH]; if (0 > index || length <= index) { - let value = this._target[0]; + let value = (this._target as any)[0]; return 0 < length ? Constant.getDefaultVal(typeof (value), value) : undefined; } - return this._target[index]; + return (this._target as any)[index]; } - let value, count = 0; + let value: T, count = 0; for (let item of this) { if (index === count++) { return item; @@ -346,7 +348,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public FirstOrDefault(predicate: (x: T) => boolean = Constant.trueFn): T { - let value; + let value: T; for (let item of this) { value = item; if (predicate(item)) { @@ -358,7 +360,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Last(predicate: (x: T) => boolean = Constant.trueFn): T { - let value, found = false; + let value: T, found = false; for (let item of this) { if (predicate(item)) { value = item; @@ -373,7 +375,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public LastOrDefault(predicate: (x: T) => boolean = Constant.trueFn): T { - let value, lastKnown, found = false; + let value: T, lastKnown: T, found = false; for (let item of this) { if (predicate(item)) { value = item; @@ -388,7 +390,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public SequenceEqual(other: Iterable, equal: (a: T, b: T) => boolean = (a, b) => a === b): boolean { - let res1, res2; + let res1: IteratorResult, res2: IteratorResult; let it1 = this[Symbol.iterator](); let it2 = other[Symbol.iterator](); do { @@ -402,7 +404,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public Single(predicate: (x: T) => boolean = Constant.trueFn): T { - let value, hasValue = false; + let value: T, hasValue = false; for (let item of this) { if (predicate(item)) { if (!hasValue) { @@ -420,8 +422,8 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public SingleOrDefault(predicate: (x: T) => boolean = - Constant.trueFn): T { - let value, lastKnown, hasValue = false; + Constant.trueFn): T { + let value: T, lastKnown: T, hasValue = false; for (let item of this) { if (predicate(item)) { if (!hasValue) { @@ -448,7 +450,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public ToArray(): Array { - let array = []; + let array: Array = []; for (let value of this) { array.push(value); } @@ -572,8 +574,8 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { public OrderBy(keySelect: (x: T) => K = Constant.selfFn, equal: (a: K, b: K) => number = (a, b) => a - b): - Enumerable { - return new OrderedLinq(this, (array) => Generator.Forward(array), + Enumerable { + return new OrderedLinq(this, (array: Array) => Generator.Forward(array), (a: T, b: T) => equal(keySelect(a), keySelect(b))); } @@ -583,7 +585,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { equal: (a: K, b: K) => number = (a, b) => a - b): Enumerable { - return new OrderedLinq(this, (array) => Generator.Reverse(array), + return new OrderedLinq(this, (array: Array) => Generator.Reverse(array), (a: T, b: T) => equal(keySelect(a), keySelect(b))); } @@ -602,7 +604,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { return this; } else { return new OrderedLinq(this, - (array) => Generator.Forward(array), (a: T, b: T) => + (array: Array) => Generator.Forward(array), (a: T, b: T) => equal(keySelect(a), keySelect(b))); } } @@ -622,7 +624,7 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { return this; } else { return new OrderedLinq(this, - (array) => Generator.Reverse(array), (a: T, b: T) => + (array: Array) => Generator.Reverse(array), (a: T, b: T) => equal(keySelect(a), keySelect(b))); } } diff --git a/lib/utilities.ts b/lib/utilities.ts index 70cd1ad..892527c 100644 --- a/lib/utilities.ts +++ b/lib/utilities.ts @@ -23,17 +23,17 @@ export var trueFn = () => true; /** Default transformer, returns self */ -export var selfFn = o => o; +export var selfFn = (o: any) => o; /** Default Grouping */ -export var defGrouping = (a, b) => { +export var defGrouping = (a: any, b: any) => { if (CONST_UNDEFINED != typeof b[CONST_KEY]) throw CONST_DUPLICATE; b[CONST_KEY] = a; return b; }; /** Returns default value for the type */ -export function getDefaultVal(type, value = undefined) : any { +export function getDefaultVal(type: any, value: any = undefined): any { if (typeof type !== CONST_STRING) throw new TypeError(CONST_NO_STRING); // Handle simple types (primitives and plain function/object) @@ -48,7 +48,7 @@ export function getDefaultVal(type, value = undefined) : any { } /** Returns a map of element bsed on extracted keys **/ -export function getKeyedMap(iterable: Iterable, keySelector: (I) => K, selElement?: (T) => E): Map> { +export function getKeyedMap(iterable: Iterable, keySelector: (i: T) => K, selElement?: (x: T) => E): Map> { let map = new Map>(); for (let value of iterable) { let key = keySelector(value); @@ -63,7 +63,7 @@ export function getKeyedMap(iterable: Iterable, keySelector: (I) => return map; } -export function getKeyedMapFast(iterable: Iterable, keySelector: (I) => K): Map> { +export function getKeyedMapFast(iterable: Iterable, keySelector: (x: T) => K): Map> { let map = new Map>(); for (let value of iterable) { let key = keySelector(value); @@ -78,7 +78,7 @@ export function getKeyedMapFast(iterable: Iterable, keySelector: (I) => return map; } -export function getKeys(iterable: Iterable, keySelector: (T) => K): Set { +export function getKeys(iterable: Iterable, keySelector: (x: T) => K): Set { let set = new Set(); if (keySelector) { for (let value of iterable) { diff --git a/tsconfig.json b/tsconfig.json index 92fe556..02e52ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es2015", "module": "umd", - "noImplicitAny": false, + "noImplicitAny": true, "noImplicitReturns": true, "removeComments": false, "declaration": true,