Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable fully strict TypeScript option #5244

Merged
merged 13 commits into from Jan 20, 2020
2 changes: 0 additions & 2 deletions spec-dtslint/tsconfig.json
Expand Up @@ -4,8 +4,6 @@
"lib": ["es2015", "dom"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"paths": {
"rxjs": ["../dist/types"],
"rxjs/operators": ["../dist/types/operators"]
Expand Down
8 changes: 4 additions & 4 deletions spec/Notification-spec.ts
Expand Up @@ -145,7 +145,7 @@ describe('Notification', () => {
const value = 'a';
let observed = false;
const n = Notification.createNext(value);
const observer = Subscriber.create((x: string) => {
const observer = Subscriber.create((x?: string) => {
expect(x).to.equal(value);
observed = true;
}, (err: any) => {
Expand All @@ -161,7 +161,7 @@ describe('Notification', () => {
it('should accept observer for error Notification', () => {
let observed = false;
const n = Notification.createError<string>();
const observer = Subscriber.create((x: string) => {
const observer = Subscriber.create((x?: string) => {
throw 'should not be called';
}, (err: any) => {
observed = true;
Expand All @@ -176,7 +176,7 @@ describe('Notification', () => {
it('should accept observer for complete Notification', () => {
let observed = false;
const n = Notification.createComplete();
const observer = Subscriber.create((x: string) => {
const observer = Subscriber.create((x?: string) => {
throw 'should not be called';
}, (err: any) => {
throw 'should not be called';
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('Notification', () => {
const value = 'a';
let observed = false;
const n = Notification.createNext(value);
const observer = Subscriber.create((x: string) => {
const observer = Subscriber.create((x?: string) => {
expect(x).to.equal(value);
observed = true;
}, (err: any) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/Observable-spec.ts
Expand Up @@ -871,7 +871,7 @@ describe('Observable.lift', () => {
next(value?: T): void {
log.push('next ' + value);
if (!this.isStopped) {
this._next(value);
this._next(value!);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec/Subscriber-spec.ts
Expand Up @@ -84,7 +84,7 @@ describe('Subscriber', () => {
});

it('should call complete observer without any arguments', () => {
let argument: Array<any> = null;
let argument: Array<any> | null = null;

const observer = {
complete: (...args: Array<any>) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/marble-testing.ts
Expand Up @@ -28,7 +28,7 @@ export function cold(marbles: string, values?: any, error?: any): ColdObservable
}

export function expectObservable(observable: Observable<any>,
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) {
unsubscriptionMarbles: string | null = null): ({ toBe: observableToBeFn }) {
if (!global.rxTestScheduler) {
throw 'tried to use expectObservable() in async test';
}
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/tests2png/diagram-test-runner.ts
Expand Up @@ -67,7 +67,7 @@ function postProcessOutputMessage(msg: TestMessage) {
}

function makeFilename(operatorLabel: string) {
return /^(\w+)/.exec(operatorLabel)[1] + '.png';
return /^(\w+)/.exec(operatorLabel)![1] + '.png';
}

type glitFn = (description: string, fn: () => void ) => any;
Expand Down
34 changes: 17 additions & 17 deletions spec/helpers/tests2png/painter.ts
@@ -1,7 +1,7 @@
/*eslint-disable no-param-reassign, no-use-before-define*/
// @ts-ignore
// @ts-ignore: Could not find a declaration file for module
import * as gm from 'gm';
// @ts-ignore
// @ts-ignore: Could not find a declaration file for module
import * as Color from 'color';
import { cloneDeep, isEqual} from 'lodash';
import { TestMessage } from '../../../src/internal/testing/TestMessage';
Expand Down Expand Up @@ -84,22 +84,22 @@ function areEqualStreamData(leftStreamData: TestStream, rightStreamData: TestStr

function measureObservableArrow(maxFrame: number, streamData: TestStream): { startX: number, endX: number } {
let startX = CANVAS_PADDING +
MESSAGES_WIDTH * (streamData.subscription.start / maxFrame);
MESSAGES_WIDTH * (streamData.subscription!.start / maxFrame);
let MAX_MESSAGES_WIDTH = CANVAS_WIDTH - CANVAS_PADDING;
let lastMessageFrame = streamData.messages
.reduce(function (acc, msg) {
let frame = msg.frame;
return frame > acc ? frame : acc;
}, 0);
let subscriptionEndX = typeof streamData.subscription.end === 'number' ? CANVAS_PADDING +
MESSAGES_WIDTH * (streamData.subscription.end / maxFrame) +
let subscriptionEndX = typeof streamData.subscription!.end === 'number' ? CANVAS_PADDING +
MESSAGES_WIDTH * (streamData.subscription!.end / maxFrame) +
OBSERVABLE_END_PADDING : undefined;
let streamEndX = startX +
MESSAGES_WIDTH * (lastMessageFrame / maxFrame) +
OBSERVABLE_END_PADDING;
let endX = (streamData.subscription.end === '100%') ?
let endX = (streamData.subscription!.end === '100%') ?
MAX_MESSAGES_WIDTH :
Math.max(streamEndX, subscriptionEndX);
Math.max(streamEndX, subscriptionEndX!);

return {startX: startX, endX: endX};
}
Expand Down Expand Up @@ -205,7 +205,7 @@ function drawMarble(out: GMObject, x: number, y: number, inclination: number, co
out = out.fill(outlineColor);
out = out.font('helvetica', 28);
out = out.draw(
'translate ' + (x - CANVAS_WIDTH * 0.5) + ',' + (y + inclination - canvasHeight * 0.5),
'translate ' + (x - CANVAS_WIDTH * 0.5) + ',' + (y + inclination - canvasHeight! * 0.5),
'gravity Center',
'text 0,0',
stringifyContent(content));
Expand Down Expand Up @@ -238,7 +238,7 @@ function drawComplete(out: GMObject, x: number, y: number,
maxFrame: number, angle: number, streamData: TestStream,
isSpecial: boolean, isGhost: boolean) {
let startX = CANVAS_PADDING +
MESSAGES_WIDTH * (streamData.subscription.start / maxFrame);
MESSAGES_WIDTH * (streamData.subscription!.start / maxFrame);
let isOverlapping = streamData.messages.some(function (msg) {
if (msg.notification.kind !== 'N') { return false; }
let msgX = startX + MESSAGES_WIDTH * (msg.frame / maxFrame);
Expand Down Expand Up @@ -272,7 +272,7 @@ function drawNestedObservable(out: GMObject, maxFrame: number, y: number, stream

function drawObservableMessages(out: GMObject, maxFrame: number, baseY: number, angle: number, streamData: TestStream, isSpecial: boolean): GMObject {
let startX = CANVAS_PADDING +
MESSAGES_WIDTH * (streamData.subscription.start / maxFrame);
MESSAGES_WIDTH * (streamData.subscription!.start / maxFrame);
let messages = streamData.messages;

messages.slice().reverse().forEach(function (message: TestMessage, reversedIndex: number) {
Expand All @@ -291,11 +291,11 @@ function drawObservableMessages(out: GMObject, maxFrame: number, baseY: number,
if (isNestedStreamData(message)) {
out = drawNestedObservable(out, maxFrame, y, message.notification.value);
} else {
out = drawMarble(out, x, y, inclination, message.notification.value, isSpecial, streamData.isGhost);
out = drawMarble(out, x, y, inclination, message.notification.value, isSpecial, streamData.isGhost!);
}
break;
case 'E': out = drawError(out, x, y, startX, angle, isSpecial, streamData.isGhost); break;
case 'C': out = drawComplete(out, x, y, maxFrame, angle, streamData, isSpecial, streamData.isGhost); break;
case 'E': out = drawError(out, x, y, startX, angle, isSpecial, streamData.isGhost!); break;
case 'C': out = drawComplete(out, x, y, maxFrame, angle, streamData, isSpecial, streamData.isGhost!); break;
default: break;
}
});
Expand All @@ -320,7 +320,7 @@ function drawOperator(out: GMObject, label: string, y: number): GMObject {
out = out.fill(BLACK_COLOR);
out = out.font('helvetica', 54);
out = out.draw(
'translate 0,' + (y + OPERATOR_HEIGHT * 0.5 - canvasHeight * 0.5),
'translate 0,' + (y + OPERATOR_HEIGHT * 0.5 - canvasHeight! * 0.5),
'gravity Center',
'text 0,0',
stringifyContent(label));
Expand All @@ -336,10 +336,10 @@ function removeDuplicateInputs(inputStreams: TestStream[], outputStreams: TestSt
inputStream.cold &&
isEqual(msg.notification.value.messages, inputStream.cold.messages);
if (passes) {
if (inputStream.cold.subscriptions.length) {
if (inputStream.cold!.subscriptions.length) {
msg.notification.value.subscription = {
start: inputStream.cold.subscriptions[0].subscribedFrame,
end: inputStream.cold.subscriptions[0].unsubscribedFrame
start: inputStream.cold!.subscriptions[0].subscribedFrame,
end: inputStream.cold!.subscriptions[0].unsubscribedFrame
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions spec/observables/IteratorObservable-spec.ts
Expand Up @@ -11,10 +11,10 @@ declare const rxTestScheduler: TestScheduler;
describe('fromIterable', () => {
it('should not accept null (or truthy-equivalent to null) iterator', () => {
expect(() => {
fromIterable(null, undefined);
fromIterable(null as any, undefined);
}).to.throw(Error, 'Iterable cannot be null');
expect(() => {
fromIterable(void 0, undefined);
fromIterable(void 0 as any, undefined);
}).to.throw(Error, 'Iterable cannot be null');
});

Expand Down Expand Up @@ -47,7 +47,7 @@ describe('fromIterable', () => {

rxTestScheduler.flush();
expect(v1).to.deep.equal(expected);
expect(v2).to.deep.equal(expected);
expect(v2!).to.deep.equal(expected);
});

it('should finalize generators if the subscription ends', () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/observables/SubscribeOnObservable-spec.ts
Expand Up @@ -28,8 +28,8 @@ describe('SubscribeOnObservable', () => {
});

it('should create observable via staic create function', () => {
const s = new SubscribeOnObservable(null, null, rxTestScheduler);
const r = SubscribeOnObservable.create(null, null, rxTestScheduler);
const s = new SubscribeOnObservable(null as any, null as any, rxTestScheduler);
const r = SubscribeOnObservable.create(null as any, null as any, rxTestScheduler);

expect(s).to.deep.equal(r);
});
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/bindCallback-spec.ts
Expand Up @@ -60,7 +60,7 @@ describe('bindCallback', () => {

boundCallback(42)
.subscribe({
next(value) { results.push(value); },
next(value: any) { results.push(value); },
complete() { results.push('done'); },
});

Expand Down
2 changes: 1 addition & 1 deletion spec/observables/bindNodeCallback-spec.ts
Expand Up @@ -281,7 +281,7 @@ describe('bindNodeCallback', () => {

it('should not swallow post-callback errors', () => {
function badFunction(callback: (error: Error, answer: number) => void): void {
callback(null, 42);
callback(null as any, 42);
throw new Error('kaboom');
}
const consoleStub = sinon.stub(console, 'warn');
Expand Down
28 changes: 14 additions & 14 deletions spec/observables/combineLatest-spec.ts
Expand Up @@ -191,7 +191,7 @@ describe('static combineLatest', () => {
it('should work with empty and error', () => {
const e1 = hot('----------|'); //empty
const e1subs = '^ !';
const e2 = hot('------#', null, 'shazbot!'); //error
const e2 = hot('------#', undefined, 'shazbot!'); //error
const e2subs = '^ !';
const expected = '------#';

Expand All @@ -203,7 +203,7 @@ describe('static combineLatest', () => {
});

it('should work with error and empty', () => {
const e1 = hot('--^---#', null, 'too bad, honk'); //error
const e1 = hot('--^---#', undefined, 'too bad, honk'); //error
const e1subs = '^ !';
const e2 = hot('--^--------|'); //empty
const e2subs = '^ !';
Expand All @@ -219,7 +219,7 @@ describe('static combineLatest', () => {
it('should work with hot and throw', () => {
const e1 = hot('-a-^--b--c--|', { a: 1, b: 2, c: 3});
const e1subs = '^ !';
const e2 = hot('---^-#', null, 'bazinga');
const e2 = hot('---^-#', undefined, 'bazinga');
const e2subs = '^ !';
const expected = '--#';

Expand All @@ -231,7 +231,7 @@ describe('static combineLatest', () => {
});

it('should work with throw and hot', () => {
const e1 = hot('---^-#', null, 'bazinga');
const e1 = hot('---^-#', undefined, 'bazinga');
const e1subs = '^ !';
const e2 = hot('-a-^--b--c--|', { a: 1, b: 2, c: 3});
const e2subs = '^ !';
Expand All @@ -245,9 +245,9 @@ describe('static combineLatest', () => {
});

it('should work with throw and throw', () => {
const e1 = hot('---^----#', null, 'jenga');
const e1 = hot('---^----#', undefined, 'jenga');
const e1subs = '^ !';
const e2 = hot('---^-#', null, 'bazinga');
const e2 = hot('---^-#', undefined, 'bazinga');
const e2subs = '^ !';
const expected = '--#';

Expand All @@ -261,7 +261,7 @@ describe('static combineLatest', () => {
it('should work with error and throw', () => {
const e1 = hot('-a-^--b--#', { a: 1, b: 2 }, 'wokka wokka');
const e1subs = '^ !';
const e2 = hot('---^-#', null, 'flurp');
const e2 = hot('---^-#', undefined, 'flurp');
const e2subs = '^ !';
const expected = '--#';

Expand All @@ -273,7 +273,7 @@ describe('static combineLatest', () => {
});

it('should work with throw and error', () => {
const e1 = hot('---^-#', null, 'flurp');
const e1 = hot('---^-#', undefined, 'flurp');
const e1subs = '^ !';
const e2 = hot('-a-^--b--#', { a: 1, b: 2 }, 'wokka wokka');
const e2subs = '^ !';
Expand All @@ -289,7 +289,7 @@ describe('static combineLatest', () => {
it('should work with never and throw', () => {
const e1 = hot('---^-----------');
const e1subs = '^ !';
const e2 = hot('---^-----#', null, 'wokka wokka');
const e2 = hot('---^-----#', undefined, 'wokka wokka');
const e2subs = '^ !';
const expected = '------#';

Expand All @@ -301,7 +301,7 @@ describe('static combineLatest', () => {
});

it('should work with throw and never', () => {
const e1 = hot('---^----#', null, 'wokka wokka');
const e1 = hot('---^----#', undefined, 'wokka wokka');
const e1subs = '^ !';
const e2 = hot('---^-----------');
const e2subs = '^ !';
Expand All @@ -317,7 +317,7 @@ describe('static combineLatest', () => {
it('should work with some and throw', () => {
const e1 = hot('---^----a---b--|', { a: 1, b: 2 });
const e1subs = '^ !';
const e2 = hot('---^--#', null, 'wokka wokka');
const e2 = hot('---^--#', undefined, 'wokka wokka');
const e2subs = '^ !';
const expected = '---#';

Expand All @@ -329,7 +329,7 @@ describe('static combineLatest', () => {
});

it('should work with throw and some', () => {
const e1 = hot('---^--#', null, 'wokka wokka');
const e1 = hot('---^--#', undefined, 'wokka wokka');
const e1subs = '^ !';
const e2 = hot('---^----a---b--|', { a: 1, b: 2 });
const e2subs = '^ !';
Expand All @@ -345,7 +345,7 @@ describe('static combineLatest', () => {
it('should handle throw after complete left', () => {
const left = hot('--a--^--b---|', { a: 1, b: 2 });
const leftSubs = '^ !';
const right = hot('-----^--------#', null, 'bad things');
const right = hot('-----^--------#', undefined, 'bad things');
const rightSubs = '^ !';
const expected = '---------#';

Expand All @@ -357,7 +357,7 @@ describe('static combineLatest', () => {
});

it('should handle throw after complete right', () => {
const left = hot('-----^--------#', null, 'bad things');
const left = hot('-----^--------#', undefined, 'bad things');
const leftSubs = '^ !';
const right = hot('--a--^--b---|', { a: 1, b: 2 });
const rightSubs = '^ !';
Expand Down