Skip to content

Commit e0f211a

Browse files
chore(typings): fixed compiler errors due to change of interfaces
1 parent e020228 commit e0f211a

File tree

8 files changed

+62
-25
lines changed

8 files changed

+62
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"commit": "git-cz",
7373
"compile_dist_amd": "tsc typings/main/ambient/es6-shim/index.d.ts ./spec/es5.d.ts ./dist/amd/src/Rx.ts ./dist/amd/src/Rx.KitchenSink.ts ./dist/amd/src/Rx.DOM.ts ./dist/amd/src/add/observable/of.ts -m amd --sourceMap --outDir ./dist/amd --target ES5 --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
7474
"compile_dist_cjs": "tsc typings/main/ambient/es6-shim/index.d.ts ./spec/es5.d.ts ./dist/cjs/src/Rx.ts ./dist/cjs/src/Rx.KitchenSink.ts ./dist/cjs/src/Rx.DOM.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
75-
"compile_dist_es6": "tsc ./spec/es5.d.ts ./dist/es6/src/Rx.ts ./dist/es6/src/Rx.KitchenSink.ts ./dist/es6/src/Rx.DOM.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
75+
"compile_dist_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/Rx.KitchenSink.ts ./dist/es6/src/Rx.DOM.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --suppressImplicitAnyIndexErrors",
7676
"cover": "npm-run-all cover_test cover_remapping",
7777
"cover_test": "rm -rf dist/cjs && tsc typings/main/ambient/es6-shim/index.d.ts src/Rx.ts src/Rx.KitchenSink.ts src/Rx.DOM.ts src/add/observable/of.ts -m commonjs --outDir dist/cjs --sourceMap --target ES5 -d && istanbul cover -x \"spec-js/**/*\" ./node_modules/mocha/bin/_mocha -- --opts spec/support/default.opts spec-js",
7878
"cover_remapping": "remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.json && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped.lcov -t lcovonly && remap-istanbul -i coverage/coverage.json -o coverage/coverage-remapped -t html",

spec/observables/from-spec.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {expect} from 'chai';
22
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
3+
import {DoneSignature, type} from '../helpers/test-helper';
34
import {$$iterator} from '../../dist/cjs/symbol/iterator';
5+
import {Observablesque} from '../../dist/cjs/Observable';
46

57
declare const {expectObservable, Symbol};
68
declare const rxTestScheduler: Rx.TestScheduler;
@@ -26,7 +28,7 @@ describe('Observable.from', () => {
2628
it('should handle an ArrayLike', function (done: MochaDone) {
2729
this.timeout(300);
2830

29-
const arrayLike = {
31+
const arrayLike: ArrayLike<number> = {
3032
length: 3,
3133
0: 1,
3234
1: 2,
@@ -64,7 +66,7 @@ describe('Observable.from', () => {
6466
it('should handle an ArrayLike with a mapFn', function (done: MochaDone) {
6567
this.timeout(300);
6668

67-
const arrayLike = {
69+
const arrayLike: ArrayLike<number> = {
6870
length: 3,
6971
0: 1,
7072
1: 2,
@@ -83,7 +85,7 @@ describe('Observable.from', () => {
8385
});
8486

8587
it('should handle an ArrayLike with a thisArg', (done: MochaDone) => {
86-
const arrayLike = {
88+
const arrayLike: ArrayLike<number> = {
8789
length: 3,
8890
0: 1,
8991
1: 2,
@@ -116,7 +118,7 @@ describe('Observable.from', () => {
116118
});
117119

118120
it('should handle an "observableque" object', (done: MochaDone) => {
119-
const observablesque = {};
121+
const observablesque: Observablesque<any> = {};
120122

121123
observablesque[Symbol.observable] = () => {
122124
return {
@@ -137,7 +139,7 @@ describe('Observable.from', () => {
137139
});
138140

139141
it('should accept scheduler for observableque object', () => {
140-
const observablesque = {};
142+
const observablesque: Observablesque<any> = <any>{};
141143

142144
observablesque[Symbol.observable] = () => {
143145
return {
@@ -166,7 +168,7 @@ describe('Observable.from', () => {
166168
});
167169

168170
it('should handle any iterable thing', (done: MochaDone) => {
169-
const iterable = {};
171+
const iterable: Iterable<string> = {};
170172
const iteratorResults = [
171173
{ value: 'one', done: false },
172174
{ value: 'two', done: false },
@@ -195,7 +197,7 @@ describe('Observable.from', () => {
195197

196198
it('should throw for non observable object', () => {
197199
const r = () => {
198-
Observable.from({}).subscribe();
200+
Observable.from(<any>{}).subscribe();
199201
};
200202

201203
expect(r).to.throw();
@@ -212,4 +214,23 @@ describe('Observable.from', () => {
212214
done();
213215
});
214216
});
217+
218+
it('should return T for ObservableLike objects', () => {
219+
type(() => {
220+
/* tslint:disable:no-unused-variable */
221+
let o1: Rx.Observable<number> = Observable.from(<number[]>[], Rx.Scheduler.asap);
222+
let o2: Rx.Observable<string> = Observable.from(<Iterable<string>>{});
223+
let o3: Rx.Observable<{ a: string }> = Observable.from(Observable.empty<{ a: string }>());
224+
let o4: Rx.Observable<{ b: number }> = Observable.from(new Promise<{b: number}>(resolve => resolve()));
225+
/* tslint:enable:no-unused-variable */
226+
});
227+
});
228+
229+
it('should return T and map for arrays', () => {
230+
type(() => {
231+
/* tslint:disable:no-unused-variable */
232+
let o1: Rx.Observable<number> = Observable.from(<number[]>[], x => x.toString(), null, Rx.Scheduler.asap);
233+
/* tslint:enable:no-unused-variable */
234+
});
235+
});
215236
});

spec/observables/zip-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Observable.zip', () => {
7777

7878
describe('with iterables', () => {
7979
it('should zip them with values', () => {
80-
const myIterator = {
80+
const myIterator: Iterable<number> = <any>{
8181
count: 0,
8282
next: function () {
8383
return { value: this.count++, done: false };
@@ -103,7 +103,7 @@ describe('Observable.zip', () => {
103103

104104
it('should only call `next` as needed', () => {
105105
let nextCalled = 0;
106-
const myIterator = {
106+
const myIterator: Iterable<number> = <any>{
107107
count: 0,
108108
next: () => {
109109
nextCalled++;

spec/operators/mergeMap-spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Observable.prototype.mergeMap', () => {
4343
it('should map values to constant rejected promises and merge', (done: MochaDone) => {
4444
const source = Rx.Observable.from([4, 3, 2, 1]);
4545
const project = function (value) {
46-
return Observable.from(Promise.reject(42));
46+
return Observable.from(Promise.reject<number>(42));
4747
};
4848

4949
source.mergeMap(project).subscribe(
@@ -82,11 +82,11 @@ describe('Observable.prototype.mergeMap', () => {
8282
it('should map values to rejected promises and merge', (done: MochaDone) => {
8383
const source = Rx.Observable.from([4, 3, 2, 1]);
8484
const project = function (value, index) {
85-
return Observable.from(Promise.reject('' + value + '-' + index));
85+
return Observable.from(Promise.reject<string>('' + value + '-' + index));
8686
};
8787

8888
source.mergeMap(project).subscribe(
89-
(x: number) => {
89+
(x: string) => {
9090
done(new Error('Subscriber next handler not supposed to be called.'));
9191
},
9292
(err: any) => {

spec/operators/zip-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Observable.prototype.zip', () => {
7777

7878
describe('with iterables', () => {
7979
it('should zip them with values', () => {
80-
const myIterator = {
80+
const myIterator: Iterable<number> = <any>{
8181
count: 0,
8282
next: function () {
8383
return { value: this.count++, done: false };
@@ -102,7 +102,7 @@ describe('Observable.prototype.zip', () => {
102102

103103
it('should only call `next` as needed', () => {
104104
let nextCalled = 0;
105-
const myIterator = {
105+
const myIterator: Iterable<number> = <any>{
106106
count: 0,
107107
next: function () {
108108
nextCalled++;

src/observable/ArrayObservable.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ export class ArrayObservable<T> extends Observable<T> {
2424
* @name of
2525
* @owner Observable
2626
*/
27-
static of<T>(...array: Array<T | Scheduler>): Observable<T> {
27+
static of<T>(item1: T, scheduler?: Scheduler): Observable<T>;
28+
static of<T>(item1: T, item2: T, scheduler?: Scheduler): Observable<T>;
29+
static of<T>(item1: T, item2: T, item3: T, scheduler?: Scheduler): Observable<T>;
30+
static of<T>(item1: T, item2: T, item3: T, item4: T, scheduler?: Scheduler): Observable<T>;
31+
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: Scheduler): Observable<T>;
32+
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: Scheduler): Observable<T>;
33+
static of<T>(...array: Array<T | Scheduler>): Observable<T>;
34+
static of<T>(...array: Array<T | Scheduler>): Observable<T> {
2835
let scheduler = <Scheduler>array[array.length - 1];
2936
if (isScheduler(scheduler)) {
3037
array.pop();

src/observable/FromObservable.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export class FromObservable<T> extends Observable<T> {
3636
* @name from
3737
* @owner Observable
3838
*/
39-
static create<T>(ish: any, mapFnOrScheduler?: Scheduler | ((x: any, y: number) => T), thisArg?: any, lastScheduler?: Scheduler): Observable<T> {
39+
static create<T>(ish: ObservableInput<T>, scheduler?: Scheduler): Observable<T>;
40+
static create<T, R>(ish: ArrayLike<T>, mapFn: (x: any, y: number) => R, thisArg?: any, scheduler?: Scheduler): Observable<R>;
41+
static create<T>(ish: ObservableInput<T>,
42+
mapFnOrScheduler?: Scheduler | ((x: any, y: number) => T),
43+
thisArg?: any,
44+
lastScheduler?: Scheduler): Observable<T> {
4045
let scheduler: Scheduler = null;
4146
let mapFn: (x: any, i: number) => T = null;
4247
if (isFunction(mapFnOrScheduler)) {

src/util/subscribeToResult.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {root} from './root';
22
import {isArray} from './isArray';
33
import {isPromise} from './isPromise';
44
import {Subscriber} from '../Subscriber';
5-
import {Observable} from '../Observable';
5+
import {Observable, ObservableInput} from '../Observable';
66
import {$$iterator} from '../symbol/iterator';
77
import {$$observable} from '../symbol/observable';
88
import {Subscription} from '../Subscription';
@@ -12,16 +12,20 @@ import {OuterSubscriber} from '../OuterSubscriber';
1212
export function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber<T, R>,
1313
result: any,
1414
outerValue?: T,
15-
outerIndex?: number): Subscription {
16-
let destination: Subscriber<R> = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);
15+
outerIndex?: number): Subscription;
16+
export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
17+
result: ObservableInput<T>,
18+
outerValue?: T,
19+
outerIndex?: number): Subscription {
20+
let destination: Subscriber<any> = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);
1721

1822
if (destination.isUnsubscribed) {
1923
return;
2024
}
2125

2226
if (result instanceof Observable) {
2327
if (result._isScalar) {
24-
destination.next(result.value);
28+
destination.next((<any>result).value);
2529
destination.complete();
2630
return;
2731
} else {
@@ -38,9 +42,9 @@ export function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber<T, R>,
3842
}
3943
} else if (isPromise(result)) {
4044
result.then(
41-
(value: any) => {
45+
(value) => {
4246
if (!destination.isUnsubscribed) {
43-
destination.next(value);
47+
destination.next(<any>value);
4448
destination.complete();
4549
}
4650
},
@@ -52,8 +56,8 @@ export function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber<T, R>,
5256
});
5357
return destination;
5458
} else if (typeof result[$$iterator] === 'function') {
55-
for (let item of result) {
56-
destination.next(item);
59+
for (let item of <any>result) {
60+
destination.next(<any>item);
5761
if (destination.isUnsubscribed) {
5862
break;
5963
}

0 commit comments

Comments
 (0)