Skip to content

Commit

Permalink
fix(typings): workaround typescript bugs when noImplicitAny or strict…
Browse files Browse the repository at this point in the history
…NullChecks are not true
  • Loading branch information
trxcllnt committed Nov 28, 2017
1 parent a8a7fc9 commit ce03239
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/asynciterable/distinct.ts
Expand Up @@ -20,7 +20,7 @@ export class DistinctAsyncIterable<TSource, TKey> extends AsyncIterableX<TSource
}

async *[Symbol.asyncIterator]() {
let set = [];
let set = [] as TKey[];

for await (let item of <AsyncIterable<TSource>>this._source) {
let key = await this._keySelector(item);
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/except.ts
Expand Up @@ -19,7 +19,7 @@ export class ExceptAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

async *[Symbol.asyncIterator]() {
let map = [];
let map = [] as TSource[];
for await (let secondItem of this._second) {
map.push(secondItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/flatten.ts
Expand Up @@ -16,7 +16,7 @@ export class FlattenAsyncIterable<TSource> extends AsyncIterableX<TSource> {
for await (let item of source) {
yield item;
}
return;
return undefined;
}
for await (let item of source) {
if (isAsyncIterable(item)) {
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/intersect.ts
Expand Up @@ -32,7 +32,7 @@ export class IntersectAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

async *[Symbol.asyncIterator]() {
let map = [];
let map = [] as TSource[];
for await (let secondItem of this._second) {
map.push(secondItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/reverse.ts
Expand Up @@ -9,7 +9,7 @@ export class ReverseAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

async *[Symbol.asyncIterator]() {
let results = [];
let results = [] as TSource[];
for await (let item of this._source) {
results.unshift(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/skiplast.ts
Expand Up @@ -11,7 +11,7 @@ export class SkipLastAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

async *[Symbol.asyncIterator]() {
let q = [];
let q = [] as TSource[];
for await (let item of this._source) {
q.push(item);
if (q.length > this._count) {
Expand Down
22 changes: 10 additions & 12 deletions src/asynciterable/takelast.ts
Expand Up @@ -11,20 +11,18 @@ export class TakeLastAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

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()!;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/toarray.ts
@@ -1,5 +1,5 @@
export async function toArray<TSource>(source: AsyncIterable<TSource>): Promise<TSource[]> {
let results = [];
let results = [] as TSource[];
for await (let item of source) {
results.push(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/asynciterable/union.ts
Expand Up @@ -19,7 +19,7 @@ export class UnionAsyncIterable<TSource> extends AsyncIterableX<TSource> {
}

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);
Expand Down
4 changes: 2 additions & 2 deletions src/asynciterable/zip.ts
Expand Up @@ -15,7 +15,7 @@ export class ZipAsyncIterable<TSource, TResult> extends AsyncIterableX<TResult>
this._fn = fn;
}

async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncIterableIterator<TResult> {
const fn = this._fn;
const sourcesLength = this._sources.length;
const its = this._sources.map(x => x[Symbol.asyncIterator]());
Expand All @@ -25,7 +25,7 @@ export class ZipAsyncIterable<TSource, TResult> extends AsyncIterableX<TResult>
const result = await its[i].next();
if (result.done) {
await Promise.all(its.map(returnAsyncIterator));
return;
return undefined;
}
values[i] = result.value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/distinct.ts
Expand Up @@ -20,7 +20,7 @@ export class DistinctIterable<TSource, TKey> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let set = [];
let set = [] as TKey[];

for (let item of this._source) {
let key = this._keySelector(item);
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/except.ts
Expand Up @@ -19,7 +19,7 @@ export class ExceptIterable<TSource> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let map = [];
let map = [] as TSource[];
for (let secondItem of this._second) {
map.push(secondItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/flatten.ts
Expand Up @@ -16,7 +16,7 @@ export class FlattenIterable<TSource> extends IterableX<TSource> {
for (let item of source) {
yield item;
}
return;
return undefined;
}
for (let item of source) {
if (isIterable(item)) {
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/intersect.ts
Expand Up @@ -28,7 +28,7 @@ export class IntersectIterable<TSource> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let map = [];
let map = [] as TSource[];
for (let secondItem of this._second) {
map.push(secondItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/reverse.ts
Expand Up @@ -9,7 +9,7 @@ export class ReverseIterable<TSource> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let results = [];
let results = [] as TSource[];
for (let item of this._source) {
results.unshift(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/skiplast.ts
Expand Up @@ -11,7 +11,7 @@ export class SkipLastIterable<TSource> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let q = [];
let q = [] as TSource[];
for (let item of this._source) {
q.push(item);
if (q.length > this._count) {
Expand Down
22 changes: 10 additions & 12 deletions src/iterable/takelast.ts
Expand Up @@ -11,20 +11,18 @@ export class TakeLastIterable<TSource> extends IterableX<TSource> {
}

*[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()!;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/toarray.ts
@@ -1,5 +1,5 @@
export function toArray<TSource>(source: Iterable<TSource>): TSource[] {
let results = [];
let results = [] as TSource[];
for (let item of source) {
results.push(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterable/union.ts
Expand Up @@ -19,7 +19,7 @@ export class UnionIterable<TSource> extends IterableX<TSource> {
}

*[Symbol.iterator]() {
let map = [];
let map = [] as TSource[];
for (let lItem of this._left) {
if (arrayIndexOf(map, lItem, this._comparer) === -1) {
map.push(lItem);
Expand Down
4 changes: 2 additions & 2 deletions src/iterable/zip.ts
Expand Up @@ -11,7 +11,7 @@ export class ZipIterable<TSource, TResult> extends IterableX<TResult> {
this._sources = sources;
this._fn = fn;
}
*[Symbol.iterator]() {
*[Symbol.iterator](): IterableIterator<TResult> {
const fn = this._fn;
const sourcesLength = this._sources.length;
const its = this._sources.map(x => x[Symbol.iterator]());
Expand All @@ -21,7 +21,7 @@ export class ZipIterable<TSource, TResult> extends IterableX<TResult> {
const result = its[index].next();
if (result.done) {
its.forEach(returnIterator);
return;
return undefined;
}
values[index] = result.value;
}
Expand Down

0 comments on commit ce03239

Please sign in to comment.