Skip to content

Commit

Permalink
refactor(compile): Activate typescript strict features
Browse files Browse the repository at this point in the history
Activate all of typescript strict features and fix everything that was broken because of it
  • Loading branch information
Sinewyk authored and staltz committed Jan 14, 2019
1 parent aa37109 commit f6f6190
Show file tree
Hide file tree
Showing 48 changed files with 106 additions and 171 deletions.
6 changes: 3 additions & 3 deletions src/extra/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SeparatorIL<T> implements InternalListener<any>, OutSender<Array<T>> {
constructor(public out: Stream<Array<T>>, private op: BufferOperator<T>) {
}

_n(t: any) {
_n(_t: any) {
this.op.flush();
}

Expand All @@ -21,7 +21,7 @@ class SeparatorIL<T> implements InternalListener<any>, OutSender<Array<T>> {
class BufferOperator<T> implements Operator<T, Array<T>> {
public type = 'buffer';
public out: Stream<Array<T>> = null as any;
private sil: InternalListener<any>;
private sil?: InternalListener<any>;
private acc: Array<T> = [];

constructor(public s: Stream<any>, public ins: Stream<T>) {
Expand All @@ -45,7 +45,7 @@ class BufferOperator<T> implements Operator<T, Array<T>> {
this.flush();
this.ins._remove(this);
this.out = null as any;
this.s._remove(this.sil);
this.s._remove(this.sil!);
this.sil = NO_IL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/extra/dropUntil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OtherIL<T> implements InternalListener<any>, OutSender<T> {
private op: DropUntilOperator<T>) {
}

_n(t: T) {
_n(_t: T) {
this.op.up();
}

Expand Down
5 changes: 2 additions & 3 deletions src/extra/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/// <reference types="node" />
import {EventEmitter} from 'events';
import {Stream, InternalProducer, InternalListener} from '../index';

export class DOMEventProducer implements InternalProducer<Event> {
public type = 'fromEvent';
private listener: EventListener | null;
private listener?: EventListener | null;

constructor(private node: EventTarget,
private eventType: string,
Expand All @@ -24,7 +23,7 @@ export class DOMEventProducer implements InternalProducer<Event> {

export class NodeEventProducer implements InternalProducer<any> {
public type = 'fromEvent';
private listener: Function | null;
private listener?: Function | null;

constructor(private node: EventEmitter, private eventName: string) { }

Expand Down
2 changes: 1 addition & 1 deletion src/extra/split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SeparatorIL<T> implements InternalListener<any>, OutSender<Stream<T>> {
private op: SplitOperator<T>) {
}

_n(t: any) {
_n(_t: any) {
this.op.up();
}

Expand Down
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function internalizeProducer<T>(producer: Producer<T> & Partial<InternalProducer
il.next = il._n;
il.error = il._e;
il.complete = il._c;
this.start(il);
this.start(il as Listener<T>);
};
producer._stop = producer.stop;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ class Observer<T> implements Listener<T> {
class FromObservable<T> implements InternalProducer<T> {
public type = 'fromObservable';
public ins: Observable<T>;
public out: Stream<T>;
public out?: Stream<T>;
private active: boolean;
private _sub: Subscription | undefined;

Expand Down Expand Up @@ -1765,7 +1765,6 @@ export class Stream<T> implements InternalListener<T> {
* @return {Stream}
*/
flatten<R>(this: Stream<Stream<R>>): T {
const p = this._prod;
return new Stream<R>(new Flatten(this)) as T & Stream<R>;
}

Expand Down Expand Up @@ -1976,7 +1975,7 @@ export class Stream<T> implements InternalListener<T> {
}

export class MemoryStream<T> extends Stream<T> {
private _v: T;
private _v?: T;
private _has: boolean = false;
constructor(producer: InternalProducer<T>) {
super(producer);
Expand All @@ -1994,14 +1993,14 @@ export class MemoryStream<T> extends Stream<T> {
const a = this._ils;
a.push(il);
if (a.length > 1) {
if (this._has) il._n(this._v);
if (this._has) il._n(this._v!);
return;
}
if (this._stopID !== NO) {
if (this._has) il._n(this._v);
if (this._has) il._n(this._v!);
clearTimeout(this._stopID);
this._stopID = NO;
} else if (this._has) il._n(this._v); else {
} else if (this._has) il._n(this._v!); else {
const p = this._prod;
if (p !== NO) p._start(this);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import buffer from '../../src/extra/buffer';
import delay from '../../src/extra/delay';
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/concat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import concat from '../../src/extra/concat';
import * as assert from 'assert';
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, {Listener, Producer} from '../../src/index';
import debounce from '../../src/extra/debounce';
import fromDiagram from '../../src/extra/fromDiagram';
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/delay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import delay from '../../src/extra/delay';
import * as assert from 'assert';
Expand Down
11 changes: 5 additions & 6 deletions tests/extra/dropRepeats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, {Stream} from '../../src/index';
import fromDiagram from '../../src/extra/fromDiagram';
import dropRepeats from '../../src/extra/dropRepeats';
Expand All @@ -21,7 +19,7 @@ describe('dropRepeats (extra)', () => {
},
});
});

it('should complete when input completes', (done: any) => {
const stream = xs.of(1).compose(dropRepeats());
const expected = [1];
Expand Down Expand Up @@ -56,7 +54,7 @@ describe('dropRepeats (extra)', () => {
});

it('should drop consecutive duplicate numbers, with a circular stream dependency', (done: any) => {
const streamProxy = xs.create();
const streamProxy = xs.create<number>();
const input = xs.of(0, 0, 1, 1, 1);
const stream = xs.merge(streamProxy, input).compose(dropRepeats());
streamProxy.imitate(stream);
Expand All @@ -71,7 +69,7 @@ describe('dropRepeats (extra)', () => {
});

input.addListener({
next: (x: number) => {},
next: () => {},
error: (err: any) => done(err),
complete: () => {
assert.equal(expected.length, 0);
Expand All @@ -82,7 +80,8 @@ describe('dropRepeats (extra)', () => {

it('should return the correct TypeScript types', (done: any) => {
const first: Stream<Event> = xs.never();
const second: Stream<Event> = first.compose(dropRepeats((x, y) => false));
const second: Stream<Event> = first.compose(dropRepeats((_x, _y) => false));
second.drop(0); // no unused variable
done();
});

Expand Down
2 changes: 0 additions & 2 deletions tests/extra/dropUntil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import concat from '../../src/extra/concat';
import dropUntil from '../../src/extra/dropUntil';
Expand Down
9 changes: 4 additions & 5 deletions tests/extra/flattenConcurrently.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, {Stream, Listener} from '../../src/index';
import flattenConcurrently from '../../src/extra/flattenConcurrently';
import * as assert from 'assert';
Expand All @@ -26,18 +24,19 @@ describe('flattenConcurrently (extra)', () => {

it('should return a flat stream with correct TypeScript types', (done: any) => {
const streamStrings: Stream<string> = Stream.create({
start: (listener: Listener<string>) => {},
start: (_listener: Listener<string>) => {},
stop: () => {}
});

const streamBooleans: Stream<boolean> = Stream.create({
start: (listener: Listener<boolean>) => {},
start: (_listener: Listener<boolean>) => {},
stop: () => {}
});

// Type checked by the compiler. Without Stream<boolean> it does not compile.
const flat: Stream<boolean> = streamStrings.map(x => streamBooleans)
const flat: Stream<boolean> = streamStrings.map(_x => streamBooleans)
.compose(flattenConcurrently);
flat.drop(0); // no unused variable
done();
});

Expand Down
4 changes: 1 addition & 3 deletions tests/extra/flattenSequentially.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import flattenSequentially from '../../src/extra/flattenSequentially';
import * as assert from 'assert';
Expand Down Expand Up @@ -156,7 +154,7 @@ describe('flattenSequentially (extra)', () => {
const expectedInner = [0, 1];

const stream = xs.of(1)
.map(i =>
.map(_i =>
xs.periodic(150).take(3) // 150ms, 300ms, 450ms, 600ms
.debug(x => assert.strictEqual(x, expectedInner.shift()))
)
Expand Down
4 changes: 1 addition & 3 deletions tests/extra/fromDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import fromDiagram from '../../src/extra/fromDiagram';
import * as assert from 'assert';
Expand Down Expand Up @@ -29,7 +27,7 @@ describe('fromDiagram (extra)', () => {
next: (x: number) => {
assert.equal(x, expected.shift());
},
error: (err) => {
error: (_err) => {
assert.equal(expected.length, 0);
done();
},
Expand Down
26 changes: 12 additions & 14 deletions tests/extra/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import {EventEmitter} from 'events';
import fromEvent from '../../src/extra/fromEvent';
import * as assert from 'assert';
function noop() {}

class FakeEventTarget implements EventTarget {
public handler: EventListener | undefined;
public event: string;
public capture: boolean;
public removedEvent: string;
public removedCapture: boolean;
public event?: string;
public capture?: boolean;
public removedEvent?: string;
public removedCapture?: boolean;

constructor() {}

Expand All @@ -27,28 +25,28 @@ class FakeEventTarget implements EventTarget {
this.capture = capture;
}

removeEventListener(e: string, handler: EventListener, capture: boolean) {
removeEventListener(e: string, _handler: EventListener, capture: boolean) {
this.removedEvent = e;
this.removedCapture = capture;

this.handler = void 0;
}

dispatchEvent(event: Event) {
dispatchEvent(_event: Event) {
return true;
}
}

class FakeEventEmitter extends EventEmitter {
public handler: Function | undefined;
public event: string | symbol;
public removedEvent: string | symbol;
public event?: string | symbol;
public removedEvent?: string | symbol;

constructor() {
super();
}

emit( eventName: string, ...args: any[] ): any {
emit(_eventName: string, ...args: any[] ): any {
if (typeof this.handler !== 'function') {
return;
}
Expand All @@ -62,7 +60,7 @@ class FakeEventEmitter extends EventEmitter {
return this;
}

removeListener(e: string, handler: Function): this {
removeListener(e: string, _handler: Function): this {
this.removedEvent = e;
this.handler = void 0;
return this;
Expand Down Expand Up @@ -118,7 +116,7 @@ describe('fromEvent (extra) - DOMEvent', () => {
const stream = fromEvent(target, 'test', true);

stream.take(1).addListener({
next: (x) => {},
next: () => {},
error: (err: any) => done(err),
complete() {
setTimeout(() => {
Expand Down Expand Up @@ -172,7 +170,7 @@ describe('fromEvent (extra) - EventEmitter', () => {
const stream = fromEvent(target, 'test');

stream.take(1).addListener({
next: (x) => {},
next: () => {},
error: (err: any) => done(err),
complete() {
setTimeout(() => {
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/pairwise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs from '../../src/index';
import pairwise from '../../src/extra/pairwise';
import * as assert from 'assert';
Expand Down
7 changes: 3 additions & 4 deletions tests/extra/sampleCombine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, { Stream } from '../../src/index';
import sampleCombine from '../../src/extra/sampleCombine';
import * as assert from 'assert';
Expand Down Expand Up @@ -30,17 +28,18 @@ describe('sampleCombine (extra)', () => {

it('should have correct TypeScript signature', (done: any) => {
const stream1 = xs.create<string>({
start: listener => { },
start: _listener => { },
stop: () => { }
});

const stream2 = xs.create<string>({
start: listener => { },
start: _listener => { },
stop: () => { }
});

const combined: Stream<[string, string]> = stream1
.compose(sampleCombine(stream2));
combined.drop(0); // no unused variables
done();
});

Expand Down
2 changes: 0 additions & 2 deletions tests/extra/split.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, { Stream } from '../../src/index';
import split from '../../src/extra/split';
import concat from '../../src/extra/concat';
Expand Down
2 changes: 0 additions & 2 deletions tests/extra/throttle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="mocha"/>
/// <reference types="node" />
import xs, {Listener, Producer} from '../../src/index';
import throttle from '../../src/extra/throttle';
import * as assert from 'assert';
Expand Down
Loading

0 comments on commit f6f6190

Please sign in to comment.