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 #3178
This commit is contained in:
3
modules/angular2/globals.d.ts
vendored
3
modules/angular2/globals.d.ts
vendored
@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
/// <reference path="typings/zone/zone.d.ts"/>
|
||||
/// <reference path="traceur-runtime.d.ts" />
|
||||
declare var assert: any;
|
||||
declare type int = number;
|
||||
|
||||
@ -32,5 +31,3 @@ interface BrowserNodeGlobal {
|
||||
setInterval: Function;
|
||||
clearInterval: Function;
|
||||
}
|
||||
|
||||
declare var global: any;
|
||||
|
@ -1,5 +1,3 @@
|
||||
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
|
||||
|
||||
import {Map, List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {ResolvedBinding, Binding, Dependency, BindingBuilder, bind} from './binding';
|
||||
import {
|
||||
|
@ -1,4 +1,3 @@
|
||||
/// <reference path="../../typings/es6-promise/es6-promise.d.ts" />
|
||||
/// <reference path="../../typings/rx/rx.d.ts" />
|
||||
|
||||
import {global, isPresent} from 'angular2/src/facade/lang';
|
||||
@ -9,7 +8,7 @@ export {Promise};
|
||||
|
||||
export interface PromiseCompleter<R> {
|
||||
promise: Promise<R>;
|
||||
resolve: (value?: R | Thenable<R>) => void;
|
||||
resolve: (value?: R | PromiseLike<R>) => void;
|
||||
reject: (error?: any, stackTrace?: string) => void;
|
||||
}
|
||||
|
||||
@ -20,7 +19,8 @@ export class PromiseWrapper {
|
||||
|
||||
// Note: We can't rename this method into `catch`, as this is not a valid
|
||||
// method name in Dart.
|
||||
static catchError<T>(promise: Promise<T>, onError: (error: any) => T | Thenable<T>): Promise<T> {
|
||||
static catchError<T>(promise: Promise<T>,
|
||||
onError: (error: any) => T | PromiseLike<T>): Promise<T> {
|
||||
return promise.catch(onError);
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ export class PromiseWrapper {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
static then<T, U>(promise: Promise<T>, success: (value: T) => U | Thenable<U>,
|
||||
rejection?: (error: any, stack?: any) => U | Thenable<U>): Promise<U> {
|
||||
static then<T, U>(promise: Promise<T>, success: (value: T) => U | PromiseLike<U>,
|
||||
rejection?: (error: any, stack?: any) => U | PromiseLike<U>): Promise<U> {
|
||||
return promise.then(success, rejection);
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ export class TimerWrapper {
|
||||
}
|
||||
|
||||
export class ObservableWrapper {
|
||||
// TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg
|
||||
static subscribe<T>(emitter: Observable, onNext: (value: T) => void,
|
||||
onThrow: (exception: any) => void = null,
|
||||
onReturn: () => void = null): Object {
|
||||
|
@ -9,7 +9,7 @@ export var StringMap = global.Object;
|
||||
// Map constructor. We work around that by manually adding the items.
|
||||
var createMapFromPairs: {(pairs: List<any>): Map<any, any>} = (function() {
|
||||
try {
|
||||
if (new Map([1, 2]).size === 2) {
|
||||
if (new Map([[1, 2]]).size === 1) {
|
||||
return function createMapFromPairs(pairs: List<any>):
|
||||
Map<any, any> { return new Map(pairs); };
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
/// <reference path="../../typings/angular-protractor/angular-protractor.d.ts" />
|
||||
/// <reference path="../../typings/jasmine/jasmine"/>
|
||||
|
||||
import webdriver = require('selenium-webdriver');
|
||||
import * as webdriver from 'selenium-webdriver';
|
||||
|
||||
export var browser: protractor.IBrowser = global['browser'];
|
||||
export var $: cssSelectorHelper = global['$'];
|
||||
|
16
modules/angular2/traceur-runtime.d.ts
vendored
16
modules/angular2/traceur-runtime.d.ts
vendored
@ -1,3 +1,19 @@
|
||||
// This file is used for TypeScript compilation to ES5 only.
|
||||
// Since this file is not included in the compilation to ES6, it is an error
|
||||
// to <reference> this file from other sources.
|
||||
// Instead it is referenced by the rootFilePaths option to the compiler.
|
||||
|
||||
// We also want the following typings to be available only when compiling to
|
||||
// ES5, because they are redundant with lib.es6.d.ts.
|
||||
/// <reference path="../angular2/typings/es6-promise/es6-promise.d.ts"/>
|
||||
|
||||
// es6-promise.d.ts chose a different name for this interface than TS lib.es6.d.ts
|
||||
// Generic Type Alises are in TS 1.6 (https://github.com/Microsoft/TypeScript/pull/3397)
|
||||
// So we cannot write:
|
||||
// declare type PromiseLike = Thenable;
|
||||
// Until then we use a workaround:
|
||||
interface PromiseLike<T> extends Thenable<T> {}
|
||||
|
||||
// Extend the ES5 standard library with some ES6 features we polyfill at runtime
|
||||
// by loading traceur-runtime.js
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"commit": "055b3172e8eb374a75826710c4d08677872620d3"
|
||||
},
|
||||
"node/node.d.ts": {
|
||||
"commit": "d5f92f93bdb49f332fa662ff1d0cc8700f02e4dc"
|
||||
"commit": "51738fdf1643d269067861b405e87503b7479236"
|
||||
},
|
||||
"rx/rx.d.ts": {
|
||||
"commit": "3882d337bb0808cde9fe4c08012508a48c135482"
|
||||
|
Reference in New Issue
Block a user