From 6093e28b61bdcce4619387d66fb451ae853c93e9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 5 Oct 2015 16:02:21 -0700 Subject: [PATCH] fix(typings): repair broken typechecks We had the typechecker disabled by accident, and many problems snuck in Fixes #4507 Closes #4508 --- modules/angular2/src/core/facade/lang.ts | 2 +- modules/angular2/src/core/util/decorators.ts | 8 +++- .../test/core/forms/directives_spec.ts | 2 +- .../angular2/test/core/forms/model_spec.ts | 2 +- .../angular2/test/core/zone/ng_zone_spec.ts | 3 +- .../src/components/button/button.ts | 4 +- .../src/components/input/input.ts | 9 +--- .../progress-linear/progress_linear.ts | 9 +--- .../src/components/radio/radio_button.ts | 1 - .../src/compiler/compiler_benchmark.ts | 3 +- .../src/tree/react/react.min.d.ts | 1 + .../src/web_workers/message_broker/index.ts | 4 +- modules/upgrade/src/angular.d.ts | 47 +++++++++++++++++++ modules/upgrade/src/metadata.ts | 5 +- modules/upgrade/src/upgrade_module.ts | 13 ++--- modules/upgrade/test/integration_spec.ts | 43 +++++++++-------- modules/upgrade/tsd.json | 12 ----- package.json | 2 +- tools/broccoli/trees/browser_tree.ts | 5 +- 19 files changed, 99 insertions(+), 76 deletions(-) create mode 100644 modules/upgrade/src/angular.d.ts delete mode 100644 modules/upgrade/tsd.json diff --git a/modules/angular2/src/core/facade/lang.ts b/modules/angular2/src/core/facade/lang.ts index 124f4be962..9fd70b4ca0 100644 --- a/modules/angular2/src/core/facade/lang.ts +++ b/modules/angular2/src/core/facade/lang.ts @@ -58,7 +58,7 @@ export function CONST_EXPR(expr: T): T { return expr; } -export function CONST(): ClassDecorator { +export function CONST(): ClassDecorator & PropertyDecorator { return (target) => target; } diff --git a/modules/angular2/src/core/util/decorators.ts b/modules/angular2/src/core/util/decorators.ts index 7a4c7fee9b..024e2eba90 100644 --- a/modules/angular2/src/core/util/decorators.ts +++ b/modules/angular2/src/core/util/decorators.ts @@ -18,7 +18,13 @@ export interface ClassDefinition { * * See {@link Class} for example of usage. */ - constructor: (Function | any[]); + constructor: Function | any[]; + + /** + * Other methods on the class. Note that values should have type 'Function' but TS requires + * all properties to have a narrower type than the index signature. + */ + [x: string]: Type | Function | any[]; } /** diff --git a/modules/angular2/test/core/forms/directives_spec.ts b/modules/angular2/test/core/forms/directives_spec.ts index 3057f291ca..0ba827ec75 100644 --- a/modules/angular2/test/core/forms/directives_spec.ts +++ b/modules/angular2/test/core/forms/directives_spec.ts @@ -93,7 +93,7 @@ export function main() { }); it("should throw when more than one custom accessor is provided", () => { - var customAccessor = new SpyValueAccessor(); + var customAccessor: ControlValueAccessor = new SpyValueAccessor(); expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError(); }); }); diff --git a/modules/angular2/test/core/forms/model_spec.ts b/modules/angular2/test/core/forms/model_spec.ts index 3279640464..33d5fe070f 100644 --- a/modules/angular2/test/core/forms/model_spec.ts +++ b/modules/angular2/test/core/forms/model_spec.ts @@ -156,7 +156,7 @@ export function main() { {"one": new Control("111"), "nested": new ControlGroup({"two": new Control("222")})}); expect(g.value).toEqual({"one": "111", "nested": {"two": "222"}}); - g.controls["nested"].controls["two"].updateValue("333"); + ((g.controls["nested"].find("two"))).updateValue("333"); expect(g.value).toEqual({"one": "111", "nested": {"two": "333"}}); }); diff --git a/modules/angular2/test/core/zone/ng_zone_spec.ts b/modules/angular2/test/core/zone/ng_zone_spec.ts index 351c7ac51b..abc63a29fb 100644 --- a/modules/angular2/test/core/zone/ng_zone_spec.ts +++ b/modules/angular2/test/core/zone/ng_zone_spec.ts @@ -11,8 +11,7 @@ import { xit, Log, isInInnerZone, - browserDetection, - TIMEOUT_INTERVAL_FOR_SLOW_BROWSERS + browserDetection } from 'angular2/test_lib'; import {PromiseCompleter, PromiseWrapper, TimerWrapper} from 'angular2/src/core/facade/async'; diff --git a/modules/angular2_material/src/components/button/button.ts b/modules/angular2_material/src/components/button/button.ts index 027d9c393f..b46ebf5c78 100644 --- a/modules/angular2_material/src/components/button/button.ts +++ b/modules/angular2_material/src/components/button/button.ts @@ -1,11 +1,11 @@ -import {Component, View, LifecycleEvent, ViewEncapsulation, OnChanges} from 'angular2/angular2'; +import {Component, View, ViewEncapsulation, OnChanges} from 'angular2/angular2'; import {TimerWrapper} from 'angular2/src/core/facade/async'; import {isPresent} from 'angular2/src/core/facade/lang'; // TODO(jelbourn): Ink ripples. -// TODO(jelbourn): Make the `isMosueDown` stuff done with one global listener. +// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener. @Component({ selector: '[md-button]:not(a), [md-fab]:not(a), [md-raised-button]:not(a)', diff --git a/modules/angular2_material/src/components/input/input.ts b/modules/angular2_material/src/components/input/input.ts index a6dd9e098f..d9b4f8da46 100644 --- a/modules/angular2_material/src/components/input/input.ts +++ b/modules/angular2_material/src/components/input/input.ts @@ -1,11 +1,4 @@ -import { - Directive, - LifecycleEvent, - Attribute, - Host, - SkipSelf, - AfterContentChecked -} from 'angular2/angular2'; +import {Directive, Attribute, Host, SkipSelf, AfterContentChecked} from 'angular2/angular2'; import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async'; diff --git a/modules/angular2_material/src/components/progress-linear/progress_linear.ts b/modules/angular2_material/src/components/progress-linear/progress_linear.ts index 137155a2d5..a4ac6b035f 100644 --- a/modules/angular2_material/src/components/progress-linear/progress_linear.ts +++ b/modules/angular2_material/src/components/progress-linear/progress_linear.ts @@ -1,11 +1,4 @@ -import { - Component, - LifecycleEvent, - View, - ViewEncapsulation, - Attribute, - OnChanges -} from 'angular2/angular2'; +import {Component, View, ViewEncapsulation, Attribute, OnChanges} from 'angular2/angular2'; import {CONST} from 'angular2/src/core/facade/lang'; import {isPresent, isBlank} from 'angular2/src/core/facade/lang'; import {Math} from 'angular2/src/core/facade/math'; diff --git a/modules/angular2_material/src/components/radio/radio_button.ts b/modules/angular2_material/src/components/radio/radio_button.ts index 94745fe654..9ff287c5f0 100644 --- a/modules/angular2_material/src/components/radio/radio_button.ts +++ b/modules/angular2_material/src/components/radio/radio_button.ts @@ -2,7 +2,6 @@ import { Component, View, ViewEncapsulation, - LifecycleEvent, Host, SkipSelf, Attribute, diff --git a/modules/benchmarks/src/compiler/compiler_benchmark.ts b/modules/benchmarks/src/compiler/compiler_benchmark.ts index 1a9590caf9..98e9e4f25e 100644 --- a/modules/benchmarks/src/compiler/compiler_benchmark.ts +++ b/modules/benchmarks/src/compiler/compiler_benchmark.ts @@ -64,12 +64,11 @@ function measureWrapper(func, desc) { class MultiplyViewResolver extends ViewResolver { _multiplyBy: number; - _cache: Map; + _cache = new Map(); constructor(multiple: number, components: Type[]) { super(); this._multiplyBy = multiple; - this._cache = new Map(); ListWrapper.forEach(components, (c) => this._fillCache(c)); } diff --git a/modules/benchmarks_external/src/tree/react/react.min.d.ts b/modules/benchmarks_external/src/tree/react/react.min.d.ts index b4842fde0a..1a6fdc30cd 100644 --- a/modules/benchmarks_external/src/tree/react/react.min.d.ts +++ b/modules/benchmarks_external/src/tree/react/react.min.d.ts @@ -1,2 +1,3 @@ export var createElement: Function; export var render: Function; +export var createClass: Function; diff --git a/modules/examples/src/web_workers/message_broker/index.ts b/modules/examples/src/web_workers/message_broker/index.ts index e4bb79f8e0..ee0a74bb86 100644 --- a/modules/examples/src/web_workers/message_broker/index.ts +++ b/modules/examples/src/web_workers/message_broker/index.ts @@ -10,9 +10,9 @@ document.getElementById("send_echo") var val = (document.getElementById("echo_input")).value; // TODO(jteplitz602): Replace default constructors with real constructors // once they're in the .d.ts file (#3926) - var args = new UiArguments(); + var args = new UiArguments("echo"); args.method = "echo"; - var fnArg = new FnArg(); + var fnArg = new FnArg(val, PRIMITIVE); fnArg.value = val; fnArg.type = PRIMITIVE; args.args = [fnArg]; diff --git a/modules/upgrade/src/angular.d.ts b/modules/upgrade/src/angular.d.ts new file mode 100644 index 0000000000..a7099734c8 --- /dev/null +++ b/modules/upgrade/src/angular.d.ts @@ -0,0 +1,47 @@ +declare namespace angular { + function module(prefix: string, dependencies?: string[]); + interface IModule { + directive(selector: string, factory: any): IModule; + value(key: string, value: any): IModule; + run(a: any); + } + interface ICompileService { + (element: Element): (IScope) => void; + } + interface IRootScopeService { + $new(): IScope; + $watch(expr: any, fn?: (a1?: any, a2?: any) => void); + $apply(): any; + $apply(exp: string): any; + $apply(exp: (scope: IScope) => any): any; + } + interface IScope extends IRootScopeService {} + interface IAngularBootstrapConfig {} + interface IDirective {} + interface IAttributes { + $observe(attr: string, fn: (v: string) => void); + } + interface ITranscludeFunction {} + interface IAugmentedJQuery { + bind(name: string, fn: () => void); + } + interface IParseService { + (expression: string): ICompiledExpression; + } + interface ICompiledExpression { + assign(context: any, value: any): any; + } + function element(e: Element); + function bootstrap(e: Element, modules: IModule[], config: IAngularBootstrapConfig); + + namespace auto { + interface IInjectorService { + get(key: string): any; + } + } + var version: {major: number}; +} + +interface Function { + $inject?: string[]; +} diff --git a/modules/upgrade/src/metadata.ts b/modules/upgrade/src/metadata.ts index 7edd6af451..feddc2e3c9 100644 --- a/modules/upgrade/src/metadata.ts +++ b/modules/upgrade/src/metadata.ts @@ -26,12 +26,13 @@ export interface AttrProp { } export interface ComponentInfo { + type: Type; selector: string; inputs: AttrProp[]; outputs: AttrProp[]; } -export function getComponentInfo(type: Type): string { +export function getComponentInfo(type: Type): ComponentInfo { var resolvedMetadata: DirectiveMetadata = directiveResolver.resolve(type); var selector = resolvedMetadata.selector; if (!selector.match(COMPONENT_SELECTOR)) { @@ -59,7 +60,7 @@ export function parseFields(names: string[]): AttrProp[] { attr: attr, bracketAttr: `[${attr}]`, parenAttr: `(${attr})`, - bracketParenAttr: `[(${attr})]` + bracketParenAttr: `[(${attr})]`, onAttr: `on${capitalAttr}`, bindAttr: `bind${capitalAttr}`, bindonAttr: `bindon${capitalAttr}` diff --git a/modules/upgrade/src/upgrade_module.ts b/modules/upgrade/src/upgrade_module.ts index 9bd62dcbf8..c7da2c8775 100644 --- a/modules/upgrade/src/upgrade_module.ts +++ b/modules/upgrade/src/upgrade_module.ts @@ -1,9 +1,7 @@ -/// +/// import { platform, - PlatformRef, - ApplicationRef, ComponentRef, bind, Directive, @@ -62,7 +60,7 @@ export class UpgradeModule { this.componentTypes.push(type); var info: ComponentInfo = getComponentInfo(type); var factory: Function = ng1ComponentDirective(info, `${this.idPrefix}${info.selector}_c`); - this.ng1Module.directive(info.selector, factory); + this.ng1Module.directive(info.selector, factory); return this; } @@ -175,7 +173,7 @@ function ng1ComponentDirective(info: ComponentInfo, idPrefix: string): Function class Ng2ComponentFacade { component: any = null; inputChangeCount: number = 0; - inputChanges: StringMap = null; + inputChanges: {[key: string]: SimpleChange} = null; hostViewRef: HostViewRef = null; changeDetector: ChangeDetectorRef = null; componentScope: angular.IScope; @@ -215,7 +213,7 @@ class Ng2ComponentFacade { prevValue = value; } this.component[prop] = value; - } + }; })(input.prop); attrs.$observe(input.attr, observeFn); } else if (attrs.hasOwnProperty(input.bindAttr)) { @@ -284,8 +282,7 @@ class Ng2ComponentFacade { ((getter) => (value) => getter(this.scope, {$event: value}))(getter) }); } else { - throw new Error( - `Missing emitter '${output.prop}' on component '${this.input.selector}'!`); + throw new Error(`Missing emitter '${output.prop}' on component '${this.info.selector}'!`); } } } diff --git a/modules/upgrade/test/integration_spec.ts b/modules/upgrade/test/integration_spec.ts index f4522e4b46..a0e6cb5a8a 100644 --- a/modules/upgrade/test/integration_spec.ts +++ b/modules/upgrade/test/integration_spec.ts @@ -12,7 +12,7 @@ import { } from 'angular2/test_lib'; import {Component, View, Inject, EventEmitter} from 'angular2/angular2'; -import {createUpgradeModule, UpgradeModule, bootstrapHybrid} from 'upgrade/upgrade'; +import {createUpgradeModule, UpgradeModule} from 'upgrade/upgrade'; export function main() { describe('upgrade: ng1 to ng2', () => { @@ -56,7 +56,8 @@ export function main() { })); describe('scope/component change-detection', () => { - it('should interleve scope and component expressions', inject([AsyncTestCompleter], (async) { + it('should interleave scope and component expressions', + inject([AsyncTestCompleter], (async) => { var log = []; var l = function(value) { log.push(value); @@ -93,7 +94,7 @@ export function main() { }); describe('binding from ng1 to ng2', () => { - it('should bind properties, events', inject([AsyncTestCompleter], (async) { + it('should bind properties, events', inject([AsyncTestCompleter], (async) => { var upgrMod: UpgradeModule = createUpgradeModule(); upgrMod.ng1Module.run(($rootScope) => { $rootScope.dataA = 'A'; @@ -133,26 +134,24 @@ export function main() { this.twoWayBEmitter = new EventEmitter(); }, onChanges: function(changes) { - var assert = - (prop, value) => { - if (this[prop] != value) { - throw new Error( - `Expected: '${prop}' to be '${value}' but was '${this[prop]}'`); - } - } + var assert = (prop, value) => { + if (this[prop] != value) { + throw new Error( + `Expected: '${prop}' to be '${value}' but was '${this[prop]}'`); + } + }; - var assertChange = - (prop, value) => { - assert(prop, value); - if (!changes[prop]) { - throw new Error(`Changes record for '${prop}' not found.`); - } - var actValue = changes[prop].currentValue; - if (actValue != value) { - throw new Error( - `Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`); - } - } + var assertChange = (prop, value) => { + assert(prop, value); + if (!changes[prop]) { + throw new Error(`Changes record for '${prop}' not found.`); + } + var actValue = changes[prop].currentValue; + if (actValue != value) { + throw new Error( + `Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`); + } + }; switch (this.onChangesCount++) { case 0: diff --git a/modules/upgrade/tsd.json b/modules/upgrade/tsd.json deleted file mode 100644 index 481137d5eb..0000000000 --- a/modules/upgrade/tsd.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "v4", - "repo": "angular/DefinitelyTyped", - "ref": "master", - "path": "typings", - "bundle": "typings/tsd.d.ts", - "installed": { - "angularjs/angular.d.ts": { - "commit": "746b9a892629060bc853e792afff536e0ec4655e" - } - } -} diff --git a/package.json b/package.json index bf40d45462..e71fade10f 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "scripts": { "preinstall": "node tools/npm/check-node-modules --purge", - "postinstall": "node tools/npm/copy-npm-shrinkwrap && node tools/chromedriverpatch.js && webdriver-manager update && bower install && gulp pubget.dart && tsd reinstall --overwrite --clean --config modules/angular2/tsd.json && tsd reinstall --overwrite --clean --config tools/tsd.json && tsd reinstall --overwrite --config modules/upgrade/tsd.json", + "postinstall": "node tools/npm/copy-npm-shrinkwrap && node tools/chromedriverpatch.js && webdriver-manager update && bower install && gulp pubget.dart && tsd reinstall --overwrite --clean --config modules/angular2/tsd.json && tsd reinstall --overwrite --clean --config tools/tsd.json", "test": "gulp test.all.js && gulp test.all.dart" }, "dependencies": { diff --git a/tools/broccoli/trees/browser_tree.ts b/tools/broccoli/trees/browser_tree.ts index 78b9192403..a434739af5 100644 --- a/tools/broccoli/trees/browser_tree.ts +++ b/tools/broccoli/trees/browser_tree.ts @@ -118,7 +118,7 @@ module.exports = function makeBrowserTree(options, destinationPath) { }); // Use TypeScript to transpile the *.ts files to ES5 - var es5Tree = compileWithTypescript(es5ModulesTree, { + var typescriptOptions = { allowNonTsExtensions: false, declaration: false, emitDecoratorMetadata: true, @@ -131,7 +131,8 @@ module.exports = function makeBrowserTree(options, destinationPath) { sourceMap: true, sourceRoot: '.', target: 'ES5' - }); + }; + var es5Tree = compileWithTypescript(es5ModulesTree, typescriptOptions); // Now we add a few more files to the es6 tree that the es5 tree should not see var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: 'angular2'});