diff --git a/packages/upgrade/src/common/angular1.ts b/packages/upgrade/src/common/angular1.ts index 0cd4fe232f..a43dba6e45 100644 --- a/packages/upgrade/src/common/angular1.ts +++ b/packages/upgrade/src/common/angular1.ts @@ -50,7 +50,7 @@ export interface IRootScopeService { $destroy(): any; $apply(exp?: Ng1Expression): any; $digest(): any; - $evalAsync(): any; + $evalAsync(exp: Ng1Expression, locals?: any): void; $on(event: string, fn?: (event?: any, ...args: any[]) => void): Function; $$childTail: IScope; $$childHead: IScope; @@ -101,7 +101,10 @@ export interface IComponent { templateUrl?: string|Function; transclude?: DirectiveTranscludeProperty; } -export interface IAttributes { $observe(attr: string, fn: (v: string) => void): void; } +export interface IAttributes { + $observe(attr: string, fn: (v: string) => void): void; + [key: string]: any; +} export interface ITranscludeFunction { // If the scope is provided, then the cloneAttachFn must be as well. (scope: IScope, cloneAttachFn: ICloneAttachFunction): IAugmentedJQuery; @@ -135,7 +138,10 @@ export interface IProvideService { decorator(token: Ng1Token, factory: IInjectable): void; } export interface IParseService { (expression: string): ICompiledExpression; } -export interface ICompiledExpression { assign(context: any, value: any): any; } +export interface ICompiledExpression { + (context: any, locals: any): any; + assign?: (context: any, value: any) => any; +} export interface IHttpBackendService { (method: string, url: string, post?: any, callback?: Function, headers?: any, timeout?: number, withCredentials?: boolean): void; @@ -211,8 +217,8 @@ function noNg() { let angular: { - bootstrap: (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig) => - void, + bootstrap: (e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) => + IInjectorService, module: (prefix: string, dependencies?: string[]) => IModule, element: (e: Element | string) => IAugmentedJQuery, version: {major: number}, @@ -256,16 +262,16 @@ export function getAngularLib(): any { } export const bootstrap = - (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void => + (e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) => angular.bootstrap(e, modules, config); -export const module = (prefix: string, dependencies?: string[]): IModule => +export const module = (prefix: string, dependencies?: string[]) => angular.module(prefix, dependencies); -export const element = (e: Element | string): IAugmentedJQuery => angular.element(e); +export const element = (e: Element | string) => angular.element(e); -export const resumeBootstrap = (): void => angular.resumeBootstrap(); +export const resumeBootstrap = () => angular.resumeBootstrap(); -export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e); +export const getTestability = (e: Element) => angular.getTestability(e); export const version = angular.version; diff --git a/packages/upgrade/src/common/downgrade_component_adapter.ts b/packages/upgrade/src/common/downgrade_component_adapter.ts index 212c469a75..1d05dc151e 100644 --- a/packages/upgrade/src/common/downgrade_component_adapter.ts +++ b/packages/upgrade/src/common/downgrade_component_adapter.ts @@ -69,7 +69,7 @@ export class DowngradeComponentAdapter { const inputs = this.componentFactory.inputs || []; for (let i = 0; i < inputs.length; i++) { const input = new PropertyBinding(inputs[i].propName, inputs[i].templateName); - let expr: any /** TODO #9100 */ = null; + let expr: string|null = null; if (attrs.hasOwnProperty(input.attr)) { const observeFn = (prop => { @@ -91,20 +91,20 @@ export class DowngradeComponentAdapter { // Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time // for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that // `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback. - let unwatch: any = this.componentScope.$watch(() => { - unwatch(''); + let unwatch: Function|null = this.componentScope.$watch(() => { + unwatch !(); unwatch = null; - observeFn((attrs as any)[input.attr]); + observeFn(attrs[input.attr]); }); } else if (attrs.hasOwnProperty(input.bindAttr)) { - expr = (attrs as any /** TODO #9100 */)[input.bindAttr]; + expr = attrs[input.bindAttr]; } else if (attrs.hasOwnProperty(input.bracketAttr)) { - expr = (attrs as any /** TODO #9100 */)[input.bracketAttr]; + expr = attrs[input.bracketAttr]; } else if (attrs.hasOwnProperty(input.bindonAttr)) { - expr = (attrs as any /** TODO #9100 */)[input.bindonAttr]; + expr = attrs[input.bindonAttr]; } else if (attrs.hasOwnProperty(input.bracketParenAttr)) { - expr = (attrs as any /** TODO #9100 */)[input.bracketParenAttr]; + expr = attrs[input.bracketParenAttr]; } if (expr != null) { const watchFn = @@ -132,24 +132,22 @@ export class DowngradeComponentAdapter { const outputs = this.componentFactory.outputs || []; for (let j = 0; j < outputs.length; j++) { const output = new PropertyBinding(outputs[j].propName, outputs[j].templateName); - let expr: any /** TODO #9100 */ = null; + let expr: string|null = null; let assignExpr = false; - const bindonAttr = - output.bindonAttr ? output.bindonAttr.substring(0, output.bindonAttr.length - 6) : null; - const bracketParenAttr = output.bracketParenAttr ? - `[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]` : - null; + const bindonAttr = output.bindonAttr.substring(0, output.bindonAttr.length - 6); + const bracketParenAttr = + `[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]`; if (attrs.hasOwnProperty(output.onAttr)) { - expr = (attrs as any /** TODO #9100 */)[output.onAttr]; + expr = attrs[output.onAttr]; } else if (attrs.hasOwnProperty(output.parenAttr)) { - expr = (attrs as any /** TODO #9100 */)[output.parenAttr]; - } else if (attrs.hasOwnProperty(bindonAttr !)) { - expr = (attrs as any /** TODO #9100 */)[bindonAttr !]; + expr = attrs[output.parenAttr]; + } else if (attrs.hasOwnProperty(bindonAttr)) { + expr = attrs[bindonAttr]; assignExpr = true; - } else if (attrs.hasOwnProperty(bracketParenAttr !)) { - expr = (attrs as any /** TODO #9100 */)[bracketParenAttr !]; + } else if (attrs.hasOwnProperty(bracketParenAttr)) { + expr = attrs[bracketParenAttr]; assignExpr = true; } @@ -162,10 +160,8 @@ export class DowngradeComponentAdapter { const emitter = this.component[output.prop] as EventEmitter; if (emitter) { emitter.subscribe({ - next: assignExpr ? - ((setter: any) => (v: any /** TODO #9100 */) => setter(this.scope, v))(setter) : - ((getter: any) => (v: any /** TODO #9100 */) => - getter(this.scope, {'$event': v}))(getter) + next: assignExpr ? (v: any) => setter !(this.scope, v) : + (v: any) => getter(this.scope, {'$event': v}) }); } else { throw new Error( diff --git a/packages/upgrade/src/static/upgrade_module.ts b/packages/upgrade/src/static/upgrade_module.ts index 70c9313e0c..9ff10c8265 100644 --- a/packages/upgrade/src/static/upgrade_module.ts +++ b/packages/upgrade/src/static/upgrade_module.ts @@ -247,7 +247,7 @@ export class UpgradeModule { const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules)); // Make sure resumeBootstrap() only exists if the current bootstrap is deferred - const windowAngular = (window as any /** TODO #???? */)['angular']; + const windowAngular = (window as any)['angular']; windowAngular.resumeBootstrap = undefined; // Bootstrap the AngularJS application inside our zone @@ -280,4 +280,4 @@ class NgAdapterInjector implements Injector { return this.modInjector.get(token, notFoundValue); } -} \ No newline at end of file +} diff --git a/packages/upgrade/test/static/integration/change_detection_spec.ts b/packages/upgrade/test/static/integration/change_detection_spec.ts index 9f43a3b0bc..3ab70f5718 100644 --- a/packages/upgrade/test/static/integration/change_detection_spec.ts +++ b/packages/upgrade/test/static/integration/change_detection_spec.ts @@ -21,8 +21,8 @@ export function main() { afterEach(() => destroyPlatform()); it('should interleave scope and component expressions', async(() => { - const log: any[] /** TODO #9100 */ = []; - const l = (value: any /** TODO #9100 */) => { + const log: string[] = []; + const l = (value: string) => { log.push(value); return value + ';'; }; @@ -46,8 +46,7 @@ export function main() { template: `{{l('2A')}}{{l('2B')}}{{l('2C')}}` }) class Ng2Component { - l: (value: any) => string; - constructor() { this.l = l; } + l = l; } @NgModule({ @@ -63,7 +62,7 @@ export function main() { .directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'})) .directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'})) .directive('ng2', downgradeComponent({component: Ng2Component})) - .run(($rootScope: any /** TODO #9100 */) => { + .run(($rootScope: angular.IRootScopeService) => { $rootScope.l = l; $rootScope.reset = () => log.length = 0; }); @@ -72,7 +71,6 @@ export function main() { html('
{{reset(); l(\'1A\');}}{{l(\'1B\')}}{{l(\'1C\')}}
'); bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => { expect(document.body.textContent).toEqual('1A;2A;ng1a;2B;ng1b;2C;1C;'); - // https://github.com/angular/angular.js/issues/12983 expect(log).toEqual(['1A', '1C', '2A', '2B', '2C', 'ng1a', 'ng1b']); }); })); @@ -88,7 +86,7 @@ export function main() { @Component({ selector: 'my-child', - template: '
{{valueFromPromise}}', + template: '
{{ valueFromPromise }}
', }) class ChildComponent { valueFromPromise: number; diff --git a/packages/upgrade/test/static/test_helpers.ts b/packages/upgrade/test/static/test_helpers.ts index 903d3732fb..31beafe518 100644 --- a/packages/upgrade/test/static/test_helpers.ts +++ b/packages/upgrade/test/static/test_helpers.ts @@ -18,7 +18,7 @@ export function bootstrap( // We bootstrap the Angular module first; then when it is ready (async) // We bootstrap the AngularJS module on the bootstrap element return platform.bootstrapModule(Ng2Module).then(ref => { - const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule; + const upgrade = ref.injector.get(UpgradeModule); upgrade.bootstrap(element, [ng1Module.name]); return upgrade; });