From aa9b617c9d5926bbbd43b2918faa267099ba2c07 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 6 Sep 2016 07:49:38 -0700 Subject: [PATCH] fix(compiler): correctly type event handler proxy functions --- .../integrationtest/src/features.ts | 25 ++++++++++++++++- .../integrationtest/src/module.ts | 27 ++++++++++++++----- modules/@angular/core/src/linker/view.ts | 6 ++--- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/modules/@angular/compiler-cli/integrationtest/src/features.ts b/modules/@angular/compiler-cli/integrationtest/src/features.ts index 29d38311e7..1d893d219f 100644 --- a/modules/@angular/compiler-cli/integrationtest/src/features.ts +++ b/modules/@angular/compiler-cli/integrationtest/src/features.ts @@ -7,7 +7,8 @@ */ import * as common from '@angular/common'; -import {CUSTOM_ELEMENTS_SCHEMA, Component, Inject, NgModule, OpaqueToken} from '@angular/core'; +import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, EventEmitter, Inject, NgModule, OpaqueToken, Output} from '@angular/core'; +import {Observable} from 'rxjs/Observable'; import {wrapInArray} from './funcs'; @@ -51,6 +52,28 @@ export class CompUsingPipes { export class CompUsingCustomElements { } +@Component({ + selector: 'cmp-event', + template: ` +
+
+
+ `, +}) +export class CompConsumingEvents { + handleDomEventVoid(e: any): void {} + handleDomEventPreventDefault(e: any): boolean { return false; } + handleDirEvent(e: any): void {} +} + +@Directive({ + selector: '[dirEvent]', +}) +export class DirPublishingEvents { + @Output('dirEvent') + dirEvent: Observable = new EventEmitter(); +} + @NgModule({schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: wrapInArray(CompUsingCustomElements)}) export class ModuleUsingCustomElements { } diff --git a/modules/@angular/compiler-cli/integrationtest/src/module.ts b/modules/@angular/compiler-cli/integrationtest/src/module.ts index 65e90d9300..c852877186 100644 --- a/modules/@angular/compiler-cli/integrationtest/src/module.ts +++ b/modules/@angular/compiler-cli/integrationtest/src/module.ts @@ -15,18 +15,33 @@ import {MultipleComponentsMyComp, NextComp} from './a/multiple_components'; import {AnimateCmp} from './animate'; import {BasicComp} from './basic'; import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components'; -import {CompUsingPipes, CompWithProviders, CompWithReferences, ModuleUsingCustomElements} from './features'; +import {CompConsumingEvents, CompUsingPipes, CompWithProviders, CompWithReferences, DirPublishingEvents, ModuleUsingCustomElements} from './features'; import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomePipeInRootModule, SomeService, someLibModuleWithProviders} from './module_fixtures'; import {CompWithNgContent, ProjectingComp} from './projection'; import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, DirectiveForQuery} from './queries'; @NgModule({ declarations: [ - SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompForChildQuery, - CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider, ProjectingComp, - CompWithChildQuery, CompWithDirectiveChild, CompWithNgContent, - CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences, CompUsingPipes, - MultipleComponentsMyComp, DirectiveForQuery, NextComp + SomeDirectiveInRootModule, + SomePipeInRootModule, + AnimateCmp, + BasicComp, + CompForChildQuery, + CompWithEntryComponents, + CompWithAnalyzeEntryComponentsProvider, + ProjectingComp, + CompWithChildQuery, + CompWithDirectiveChild, + CompWithNgContent, + CompUsingRootModuleDirectiveAndPipe, + CompWithProviders, + CompWithReferences, + CompUsingPipes, + CompConsumingEvents, + DirPublishingEvents, + MultipleComponentsMyComp, + DirectiveForQuery, + NextComp, ], imports: [ BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements, diff --git a/modules/@angular/core/src/linker/view.ts b/modules/@angular/core/src/linker/view.ts index 21dee30fdb..198157628e 100644 --- a/modules/@angular/core/src/linker/view.ts +++ b/modules/@angular/core/src/linker/view.ts @@ -351,7 +351,7 @@ export abstract class AppView { } } - eventHandler(cb: Function): Function { return cb; } + eventHandler(cb: (event?: E) => R): (event?: E) => R { return cb; } throwDestroyedError(details: string): void { throw new ViewDestroyedError(details); } } @@ -434,9 +434,9 @@ export class DebugAppView extends AppView { } } - eventHandler(cb: Function): Function { + eventHandler(cb: (event?: E) => R): (event?: E) => R { var superHandler = super.eventHandler(cb); - return (event: any) => { + return (event?: any) => { this._resetDebug(); try { return superHandler(event);