Skip to content

Commit 643c717

Browse files
committed
chore(build): enable type-checking for TypeScript ES6 emit.
This requires delicate handling of type definitions which collide, because we use TypeScript-provided lib.d.ts for --target=es5 and lib.es6.d.ts for --target=es6. We need to include our polyfill typings only in the --target=es5 case, and the usages have to be consistent with lib.es6.d.ts. Also starting with this change we now typecheck additional modules, so this fixes a bunch of wrong typings which were never checked before. Fixes angular#3178
1 parent 40a3cd2 commit 643c717

File tree

35 files changed

+88
-83
lines changed

35 files changed

+88
-83
lines changed

modules/angular2/globals.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
/// <reference path="typings/zone/zone.d.ts"/>
6-
/// <reference path="traceur-runtime.d.ts" />
76
declare var assert: any;
87
declare type int = number;
98

@@ -32,5 +31,3 @@ interface BrowserNodeGlobal {
3231
setInterval: Function;
3332
clearInterval: Function;
3433
}
35-
36-
declare var global: any;

modules/angular2/src/di/injector.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
2-
31
import {Map, List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
42
import {ResolvedBinding, Binding, Dependency, BindingBuilder, bind} from './binding';
53
import {

modules/angular2/src/facade/async.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
21
/// <reference path="../../typings/rx/rx.d.ts" />
32

43
import {global, isPresent} from 'angular2/src/facade/lang';
@@ -9,7 +8,7 @@ export {Promise};
98

109
export interface PromiseCompleter<R> {
1110
promise: Promise<R>;
12-
resolve: (value?: R | Thenable<R>) => void;
11+
resolve: (value?: R | PromiseLike<R>) => void;
1312
reject: (error?: any, stackTrace?: string) => void;
1413
}
1514

@@ -20,7 +19,8 @@ export class PromiseWrapper {
2019

2120
// Note: We can't rename this method into `catch`, as this is not a valid
2221
// method name in Dart.
23-
static catchError<T>(promise: Promise<T>, onError: (error: any) => T | Thenable<T>): Promise<T> {
22+
static catchError<T>(promise: Promise<T>,
23+
onError: (error: any) => T | PromiseLike<T>): Promise<T> {
2424
return promise.catch(onError);
2525
}
2626

@@ -29,8 +29,8 @@ export class PromiseWrapper {
2929
return Promise.all(promises);
3030
}
3131

32-
static then<T, U>(promise: Promise<T>, success: (value: T) => U | Thenable<U>,
33-
rejection?: (error: any, stack?: any) => U | Thenable<U>): Promise<U> {
32+
static then<T, U>(promise: Promise<T>, success: (value: T) => U | PromiseLike<U>,
33+
rejection?: (error: any, stack?: any) => U | PromiseLike<U>): Promise<U> {
3434
return promise.then(success, rejection);
3535
}
3636

@@ -66,6 +66,7 @@ export class TimerWrapper {
6666
}
6767

6868
export class ObservableWrapper {
69+
// TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg
6970
static subscribe<T>(emitter: Observable, onNext: (value: T) => void,
7071
onThrow: (exception: any) => void = null,
7172
onReturn: () => void = null): Object {

modules/angular2/src/facade/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export var StringMap = global.Object;
99
// Map constructor. We work around that by manually adding the items.
1010
var createMapFromPairs: {(pairs: List<any>): Map<any, any>} = (function() {
1111
try {
12-
if (new Map([1, 2]).size === 2) {
12+
if (new Map([[1, 2]]).size === 1) {
1313
return function createMapFromPairs(pairs: List<any>):
1414
Map<any, any> { return new Map(pairs); };
1515
}

modules/angular2/src/test_lib/e2e_util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference path="../../typings/angular-protractor/angular-protractor.d.ts" />
33
/// <reference path="../../typings/jasmine/jasmine"/>
44

5-
import webdriver = require('selenium-webdriver');
5+
import * as webdriver from 'selenium-webdriver';
66

77
export var browser: protractor.IBrowser = global['browser'];
88
export var $: cssSelectorHelper = global['$'];

modules/angular2/traceur-runtime.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// This file is used for TypeScript compilation to ES5 only.
2+
// Since this file is not included in the compilation to ES6, it is an error
3+
// to <reference> this file from other sources.
4+
// Instead it is referenced by the rootFilePaths option to the compiler.
5+
6+
// We also want the following typings to be available only when compiling to
7+
// ES5, because they are redundant with lib.es6.d.ts.
8+
/// <reference path="../angular2/typings/es6-promise/es6-promise.d.ts"/>
9+
10+
// es6-promise.d.ts chose a different name for this interface than TS lib.es6.d.ts
11+
// Generic Type Alises are in TS 1.6 (https://github.com/Microsoft/TypeScript/pull/3397)
12+
// So we cannot write:
13+
// declare type PromiseLike = Thenable;
14+
// Until then we use a workaround:
15+
interface PromiseLike<T> extends Thenable<T> {}
16+
117
// Extend the ES5 standard library with some ES6 features we polyfill at runtime
218
// by loading traceur-runtime.js
319

modules/angular2/tsd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"commit": "055b3172e8eb374a75826710c4d08677872620d3"
1616
},
1717
"node/node.d.ts": {
18-
"commit": "d5f92f93bdb49f332fa662ff1d0cc8700f02e4dc"
18+
"commit": "51738fdf1643d269067861b405e87503b7479236"
1919
},
2020
"rx/rx.d.ts": {
2121
"commit": "3882d337bb0808cde9fe4c08012508a48c135482"

modules/angular2_material/src/components/grid_list/grid_list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ export class MdGridTile {
260260
}
261261

262262
set rowspan(value) {
263-
this._rowspan = isString(value) ? NumberWrapper.parseInt(value, 10) : <number>value;
263+
this._rowspan = isString(value) ? NumberWrapper.parseInt(<any>value, 10) : <number>value;
264264
}
265265

266266
get rowspan() {
267267
return this._rowspan;
268268
}
269269

270270
set colspan(value) {
271-
this._colspan = isString(value) ? NumberWrapper.parseInt(value, 10) : <number>value;
271+
this._colspan = isString(value) ? NumberWrapper.parseInt(<any>value, 10) : <number>value;
272272
}
273273

274274
get colspan() {

modules/angular2_material/src/components/input/input.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class MdInputContainer {
4949
// classes based on the input state.
5050
ObservableWrapper.subscribe(input.mdChange, value => { this.inputHasValue = value != ''; });
5151

52-
ObservableWrapper.subscribe(input.mdFocusChange, hasFocus => {this.inputHasFocus = hasFocus});
52+
ObservableWrapper.subscribe<boolean>(input.mdFocusChange,
53+
hasFocus => this.inputHasFocus = hasFocus);
5354
}
5455
}
5556

modules/benchmarks/src/naive_infinite_scroll/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class RawEntity {
6666
var pieces = key.split('.');
6767
var last = ListWrapper.last(pieces);
6868
pieces.length = pieces.length - 1;
69-
var target = _resolve(pieces, this);
69+
var target = this._resolve(pieces, this);
7070
if (target == null) {
7171
return null;
7272
}
@@ -81,7 +81,7 @@ export class RawEntity {
8181
var pieces = key.split('.');
8282
var last = ListWrapper.last(pieces);
8383
pieces.length = pieces.length - 1;
84-
var target = _resolve(pieces, this);
84+
var target = this._resolve(pieces, this);
8585
target[last] = value;
8686
}
8787

@@ -92,7 +92,7 @@ export class RawEntity {
9292
var pieces = key.split('.');
9393
var last = ListWrapper.last(pieces);
9494
pieces.length = pieces.length - 1;
95-
var target = _resolve(pieces, this);
95+
var target = this._resolve(pieces, this);
9696
return target.remove(last);
9797
}
9898

0 commit comments

Comments
 (0)