Skip to content

Commit 642c334

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

File tree

8 files changed

+62
-26
lines changed

8 files changed

+62
-26
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {expect} from 'chai';
22
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
33
import {$$iterator} from '../../dist/cjs/symbol/iterator';
4+
import {Observablesque} from '../../dist/cjs/Observable';
45

5-
declare const {expectObservable, Symbol};
6+
declare const {expectObservable, Symbol, type};
67
declare const rxTestScheduler: Rx.TestScheduler;
78
const Observable = Rx.Observable;
89

@@ -26,7 +27,7 @@ describe('Observable.from', () => {
2627
it('should handle an ArrayLike', function (done: MochaDone) {
2728
this.timeout(300);
2829

29-
const arrayLike = {
30+
const arrayLike: ArrayLike<number> = {
3031
length: 3,
3132
0: 1,
3233
1: 2,
@@ -64,7 +65,7 @@ describe('Observable.from', () => {
6465
it('should handle an ArrayLike with a mapFn', function (done: MochaDone) {
6566
this.timeout(300);
6667

67-
const arrayLike = {
68+
const arrayLike: ArrayLike<number> = {
6869
length: 3,
6970
0: 1,
7071
1: 2,
@@ -83,7 +84,7 @@ describe('Observable.from', () => {
8384
});
8485

8586
it('should handle an ArrayLike with a thisArg', (done: MochaDone) => {
86-
const arrayLike = {
87+
const arrayLike: ArrayLike<number> = {
8788
length: 3,
8889
0: 1,
8990
1: 2,
@@ -116,7 +117,7 @@ describe('Observable.from', () => {
116117
});
117118

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

121122
observablesque[Symbol.observable] = () => {
122123
return {
@@ -137,7 +138,7 @@ describe('Observable.from', () => {
137138
});
138139

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

142143
observablesque[Symbol.observable] = () => {
143144
return {
@@ -166,7 +167,7 @@ describe('Observable.from', () => {
166167
});
167168

168169
it('should handle any iterable thing', (done: MochaDone) => {
169-
const iterable = {};
170+
const iterable: Iterable<string> = {};
170171
const iteratorResults = [
171172
{ value: 'one', done: false },
172173
{ value: 'two', done: false },
@@ -195,7 +196,7 @@ describe('Observable.from', () => {
195196

196197
it('should throw for non observable object', () => {
197198
const r = () => {
198-
Observable.from({}).subscribe();
199+
Observable.from(<any>{}).subscribe();
199200
};
200201

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

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)