Skip to content

Commit

Permalink
feat(typescript): updated to typescript 2.4.0 (rc) (#2684)
Browse files Browse the repository at this point in the history
Fixed code that was failing due to compiler upgrade

Several methods are now using default generic arguments, which were introduced in ts2.3
  • Loading branch information
david-driscoll authored and benlesh committed Jun 20, 2017
1 parent 12bc7fe commit 766b5a7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
{
"name": "Andre Staltz",
"email": "andre@staltz.com"
},
{
"name": "David Driscoll",
"email": "david.driscoll@gmail.com"
}
],
"license": "Apache-2.0",
Expand Down Expand Up @@ -172,32 +176,32 @@
"gzip-size": "^3.0.0",
"http-server": "^0.9.0",
"husky": "^0.13.3",
"lint-staged": "3.2.5",
"lodash": "^4.15.0",
"lint-staged": "^4.0.0",
"lodash": "^4.17.4",
"madge": "^1.4.3",
"markdown-doctest": "^0.9.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"mocha": "^3.4.2",
"mocha-in-sauce": "0.0.1",
"npm-run-all": "^4.0.2",
"npm-scripts-info": "^0.3.4",
"nyc": "^10.2.0",
"nyc": "^11.0.2",
"opn-cli": "^3.1.0",
"platform": "^1.3.1",
"promise": "^7.1.1",
"protractor": "^3.1.1",
"protractor": "^5.1.2",
"rollup": "0.36.3",
"rollup-plugin-inject": "^2.0.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rx": "latest",
"shx": "^0.2.2",
"sinon": "^2.1.0",
"sinon-chai": "^2.9.0",
"sinon": "^2.3.5",
"sinon-chai": "^2.11.0",
"source-map-support": "^0.4.0",
"tslib": "^1.7.1",
"tslint": "^5.4.3",
"typescript": "~2.3.0",
"typescript": "^2.4.0",
"validate-commit-msg": "^2.3.1",
"watch": "^1.0.1",
"webpack": "^1.13.1",
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ class MockXMLHttpRequest {

private previousRequest: MockXMLHttpRequest;

protected responseType: string = '';
protected responseType: XMLHttpRequestResponseType = '';
private eventHandlers: Array<any> = [];
private readyState: number = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Observable<T> implements Subscribable<T> {
* @param {Operator} operator the operator defining the operation to take on the observable
* @return {Observable} a new observable with the Operator applied
*/
lift<R>(operator: Operator<T, R>): Observable<R> {
lift<R = T>(operator: Operator<T, R>): Observable<R> {
const observable = new Observable<R>();
observable.source = this;
observable.operator = operator;
Expand Down
26 changes: 13 additions & 13 deletions src/operator/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { subscribeToResult } from '../util/subscribeToResult';
*
* Observable.of(1, 2, 3, 4, 5)
* .map(n => {
* if (n == 4) {
* throw 'four!';
* if (n == 4) {
* throw 'four!';
* }
* return n;
* return n;
* })
* .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
* .subscribe(x => console.log(x));
Expand All @@ -27,10 +27,10 @@ import { subscribeToResult } from '../util/subscribeToResult';
*
* Observable.of(1, 2, 3, 4, 5)
* .map(n => {
* if (n === 4) {
* throw 'four!';
* if (n === 4) {
* throw 'four!';
* }
* return n;
* return n;
* })
* .catch((err, caught) => caught)
* .take(30)
Expand Down Expand Up @@ -64,16 +64,16 @@ import { subscribeToResult } from '../util/subscribeToResult';
* @name catch
* @owner Observable
*/
export function _catch<T, R>(this: Observable<T>, selector: (err: any, caught: Observable<T>) => ObservableInput<R>): Observable<T | R> {
export function _catch<T, R = T>(this: Observable<T>, selector: (err: any, caught: Observable<R>) => ObservableInput<R>): Observable<R> {
const operator = new CatchOperator(selector);
const caught = this.lift(operator);
return (operator.caught = caught);
}

class CatchOperator<T, R> implements Operator<T, T | R> {
caught: Observable<T>;
class CatchOperator<T, R = T> implements Operator<T, R> {
caught: Observable<R>;

constructor(private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>) {
constructor(private selector: (err: any, caught: Observable<R>) => ObservableInput<R>) {
}

call(subscriber: Subscriber<R>, source: any): any {
Expand All @@ -86,10 +86,10 @@ class CatchOperator<T, R> implements Operator<T, T | R> {
* @ignore
* @extends {Ignored}
*/
class CatchSubscriber<T, R> extends OuterSubscriber<T, T | R> {
class CatchSubscriber<T, R> extends OuterSubscriber<T, R> {
constructor(destination: Subscriber<any>,
private selector: (err: any, caught: Observable<T>) => ObservableInput<T | R>,
private caught: Observable<T>) {
private selector: (err: any, caught: Observable<R>) => ObservableInput<R>,
private caught: Observable<R>) {
super(destination);
}

Expand Down
11 changes: 5 additions & 6 deletions src/operator/defaultIfEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';

/* tslint:disable:max-line-length */
export function defaultIfEmpty<T>(this: Observable<T>, defaultValue?: T): Observable<T>;
export function defaultIfEmpty<T, R>(this: Observable<T>, defaultValue?: R): Observable<T | R>;
export function defaultIfEmpty<T, R = T>(this: Observable<T>, defaultValue?: R): Observable<R>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -37,16 +36,16 @@ export function defaultIfEmpty<T, R>(this: Observable<T>, defaultValue?: R): Obs
* @method defaultIfEmpty
* @owner Observable
*/
export function defaultIfEmpty<T, R>(this: Observable<T>, defaultValue: R = null): Observable<T | R> {
export function defaultIfEmpty<T, R = T>(this: Observable<T>, defaultValue: R = null): Observable<R> {
return this.lift(new DefaultIfEmptyOperator(defaultValue));
}

class DefaultIfEmptyOperator<T, R> implements Operator<T, T | R> {
class DefaultIfEmptyOperator<T, R> implements Operator<T, R> {

constructor(private defaultValue: R) {
}

call(subscriber: Subscriber<T | R>, source: any): any {
call(subscriber: Subscriber<R>, source: any): any {
return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
}
}
Expand All @@ -59,7 +58,7 @@ class DefaultIfEmptyOperator<T, R> implements Operator<T, T | R> {
class DefaultIfEmptySubscriber<T, R> extends Subscriber<T> {
private isEmpty: boolean = true;

constructor(destination: Subscriber<T | R>, private defaultValue: R) {
constructor(destination: Subscriber<R>, private defaultValue: R) {
super(destination);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/isPromise.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isPromise<T>(value: any | Promise<T>): value is Promise<T> {
export function isPromise<T>(value: any | PromiseLike<T>): value is PromiseLike<T> {
return value && typeof (<any>value).subscribe !== 'function' && typeof (value as any).then === 'function';
}

0 comments on commit 766b5a7

Please sign in to comment.