From ce0323976b473ea2ded454dc9ee8f50e3a64d6ab Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Tue, 28 Nov 2017 01:57:49 -0800 Subject: [PATCH] fix(typings): workaround typescript bugs when noImplicitAny or strictNullChecks are not true --- src/asynciterable/distinct.ts | 2 +- src/asynciterable/except.ts | 2 +- src/asynciterable/flatten.ts | 2 +- src/asynciterable/intersect.ts | 2 +- src/asynciterable/reverse.ts | 2 +- src/asynciterable/skiplast.ts | 2 +- src/asynciterable/takelast.ts | 22 ++++++++++------------ src/asynciterable/toarray.ts | 2 +- src/asynciterable/union.ts | 2 +- src/asynciterable/zip.ts | 4 ++-- src/iterable/distinct.ts | 2 +- src/iterable/except.ts | 2 +- src/iterable/flatten.ts | 2 +- src/iterable/intersect.ts | 2 +- src/iterable/reverse.ts | 2 +- src/iterable/skiplast.ts | 2 +- src/iterable/takelast.ts | 22 ++++++++++------------ src/iterable/toarray.ts | 2 +- src/iterable/union.ts | 2 +- src/iterable/zip.ts | 4 ++-- 20 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/asynciterable/distinct.ts b/src/asynciterable/distinct.ts index 46c4b4fc..a4003f17 100644 --- a/src/asynciterable/distinct.ts +++ b/src/asynciterable/distinct.ts @@ -20,7 +20,7 @@ export class DistinctAsyncIterable extends AsyncIterableX>this._source) { let key = await this._keySelector(item); diff --git a/src/asynciterable/except.ts b/src/asynciterable/except.ts index a3cb413d..66da08ca 100644 --- a/src/asynciterable/except.ts +++ b/src/asynciterable/except.ts @@ -19,7 +19,7 @@ export class ExceptAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - let map = []; + let map = [] as TSource[]; for await (let secondItem of this._second) { map.push(secondItem); } diff --git a/src/asynciterable/flatten.ts b/src/asynciterable/flatten.ts index 375d263d..2d8a6ff4 100644 --- a/src/asynciterable/flatten.ts +++ b/src/asynciterable/flatten.ts @@ -16,7 +16,7 @@ export class FlattenAsyncIterable extends AsyncIterableX { for await (let item of source) { yield item; } - return; + return undefined; } for await (let item of source) { if (isAsyncIterable(item)) { diff --git a/src/asynciterable/intersect.ts b/src/asynciterable/intersect.ts index 54911368..d813e460 100644 --- a/src/asynciterable/intersect.ts +++ b/src/asynciterable/intersect.ts @@ -32,7 +32,7 @@ export class IntersectAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - let map = []; + let map = [] as TSource[]; for await (let secondItem of this._second) { map.push(secondItem); } diff --git a/src/asynciterable/reverse.ts b/src/asynciterable/reverse.ts index 96e6bb59..ca9eb045 100644 --- a/src/asynciterable/reverse.ts +++ b/src/asynciterable/reverse.ts @@ -9,7 +9,7 @@ export class ReverseAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - let results = []; + let results = [] as TSource[]; for await (let item of this._source) { results.unshift(item); } diff --git a/src/asynciterable/skiplast.ts b/src/asynciterable/skiplast.ts index afd7cea2..af9eaa4c 100644 --- a/src/asynciterable/skiplast.ts +++ b/src/asynciterable/skiplast.ts @@ -11,7 +11,7 @@ export class SkipLastAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - let q = []; + let q = [] as TSource[]; for await (let item of this._source) { q.push(item); if (q.length > this._count) { diff --git a/src/asynciterable/takelast.ts b/src/asynciterable/takelast.ts index a9ab95b3..b912005a 100644 --- a/src/asynciterable/takelast.ts +++ b/src/asynciterable/takelast.ts @@ -11,20 +11,18 @@ export class TakeLastAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - if (this._count === 0) { - return; - } - - let q = []; - for await (let item of this._source) { - if (q.length >= this._count) { - q.shift(); + if (this._count > 0) { + let q = [] as TSource[]; + for await (let item of this._source) { + if (q.length >= this._count) { + q.shift(); + } + q.push(item); } - q.push(item); - } - while (q.length > 0) { - yield q.shift()!; + while (q.length > 0) { + yield q.shift()!; + } } } } diff --git a/src/asynciterable/toarray.ts b/src/asynciterable/toarray.ts index e3e63c4b..7ffd0c7f 100644 --- a/src/asynciterable/toarray.ts +++ b/src/asynciterable/toarray.ts @@ -1,5 +1,5 @@ export async function toArray(source: AsyncIterable): Promise { - let results = []; + let results = [] as TSource[]; for await (let item of source) { results.push(item); } diff --git a/src/asynciterable/union.ts b/src/asynciterable/union.ts index 95949cde..e5270ad7 100644 --- a/src/asynciterable/union.ts +++ b/src/asynciterable/union.ts @@ -19,7 +19,7 @@ export class UnionAsyncIterable extends AsyncIterableX { } async *[Symbol.asyncIterator]() { - let map = []; + let map = [] as TSource[]; for await (let lItem of this._left) { if ((await arrayIndexOfAsync(map, lItem, this._comparer)) === -1) { map.push(lItem); diff --git a/src/asynciterable/zip.ts b/src/asynciterable/zip.ts index 6ba0b157..d732d865 100644 --- a/src/asynciterable/zip.ts +++ b/src/asynciterable/zip.ts @@ -15,7 +15,7 @@ export class ZipAsyncIterable extends AsyncIterableX this._fn = fn; } - async *[Symbol.asyncIterator]() { + async *[Symbol.asyncIterator](): AsyncIterableIterator { const fn = this._fn; const sourcesLength = this._sources.length; const its = this._sources.map(x => x[Symbol.asyncIterator]()); @@ -25,7 +25,7 @@ export class ZipAsyncIterable extends AsyncIterableX const result = await its[i].next(); if (result.done) { await Promise.all(its.map(returnAsyncIterator)); - return; + return undefined; } values[i] = result.value; } diff --git a/src/iterable/distinct.ts b/src/iterable/distinct.ts index ac1685d6..96a8bf66 100644 --- a/src/iterable/distinct.ts +++ b/src/iterable/distinct.ts @@ -20,7 +20,7 @@ export class DistinctIterable extends IterableX { } *[Symbol.iterator]() { - let set = []; + let set = [] as TKey[]; for (let item of this._source) { let key = this._keySelector(item); diff --git a/src/iterable/except.ts b/src/iterable/except.ts index fec125a5..2b9f7d26 100644 --- a/src/iterable/except.ts +++ b/src/iterable/except.ts @@ -19,7 +19,7 @@ export class ExceptIterable extends IterableX { } *[Symbol.iterator]() { - let map = []; + let map = [] as TSource[]; for (let secondItem of this._second) { map.push(secondItem); } diff --git a/src/iterable/flatten.ts b/src/iterable/flatten.ts index e0db5b56..b25325a0 100644 --- a/src/iterable/flatten.ts +++ b/src/iterable/flatten.ts @@ -16,7 +16,7 @@ export class FlattenIterable extends IterableX { for (let item of source) { yield item; } - return; + return undefined; } for (let item of source) { if (isIterable(item)) { diff --git a/src/iterable/intersect.ts b/src/iterable/intersect.ts index 75b76e70..997fb59b 100644 --- a/src/iterable/intersect.ts +++ b/src/iterable/intersect.ts @@ -28,7 +28,7 @@ export class IntersectIterable extends IterableX { } *[Symbol.iterator]() { - let map = []; + let map = [] as TSource[]; for (let secondItem of this._second) { map.push(secondItem); } diff --git a/src/iterable/reverse.ts b/src/iterable/reverse.ts index b931c738..b4ea323c 100644 --- a/src/iterable/reverse.ts +++ b/src/iterable/reverse.ts @@ -9,7 +9,7 @@ export class ReverseIterable extends IterableX { } *[Symbol.iterator]() { - let results = []; + let results = [] as TSource[]; for (let item of this._source) { results.unshift(item); } diff --git a/src/iterable/skiplast.ts b/src/iterable/skiplast.ts index 8c048645..a22d26ce 100644 --- a/src/iterable/skiplast.ts +++ b/src/iterable/skiplast.ts @@ -11,7 +11,7 @@ export class SkipLastIterable extends IterableX { } *[Symbol.iterator]() { - let q = []; + let q = [] as TSource[]; for (let item of this._source) { q.push(item); if (q.length > this._count) { diff --git a/src/iterable/takelast.ts b/src/iterable/takelast.ts index 59b9fc67..5cc2e634 100644 --- a/src/iterable/takelast.ts +++ b/src/iterable/takelast.ts @@ -11,20 +11,18 @@ export class TakeLastIterable extends IterableX { } *[Symbol.iterator]() { - if (this._count === 0) { - return; - } - - let q = []; - for (let item of this._source) { - if (q.length >= this._count) { - q.shift(); + if (this._count > 0) { + let q = [] as TSource[]; + for (let item of this._source) { + if (q.length >= this._count) { + q.shift(); + } + q.push(item); } - q.push(item); - } - while (q.length > 0) { - yield q.shift()!; + while (q.length > 0) { + yield q.shift()!; + } } } } diff --git a/src/iterable/toarray.ts b/src/iterable/toarray.ts index fc9eb217..4fc9b829 100644 --- a/src/iterable/toarray.ts +++ b/src/iterable/toarray.ts @@ -1,5 +1,5 @@ export function toArray(source: Iterable): TSource[] { - let results = []; + let results = [] as TSource[]; for (let item of source) { results.push(item); } diff --git a/src/iterable/union.ts b/src/iterable/union.ts index eeaecc9e..c977b15a 100644 --- a/src/iterable/union.ts +++ b/src/iterable/union.ts @@ -19,7 +19,7 @@ export class UnionIterable extends IterableX { } *[Symbol.iterator]() { - let map = []; + let map = [] as TSource[]; for (let lItem of this._left) { if (arrayIndexOf(map, lItem, this._comparer) === -1) { map.push(lItem); diff --git a/src/iterable/zip.ts b/src/iterable/zip.ts index cb39c2fb..7f86544f 100644 --- a/src/iterable/zip.ts +++ b/src/iterable/zip.ts @@ -11,7 +11,7 @@ export class ZipIterable extends IterableX { this._sources = sources; this._fn = fn; } - *[Symbol.iterator]() { + *[Symbol.iterator](): IterableIterator { const fn = this._fn; const sourcesLength = this._sources.length; const its = this._sources.map(x => x[Symbol.iterator]()); @@ -21,7 +21,7 @@ export class ZipIterable extends IterableX { const result = its[index].next(); if (result.done) { its.forEach(returnIterator); - return; + return undefined; } values[index] = result.value; }