fix(compiler): correctly type event handler proxy functions

This commit is contained in:
Tobias Bosch 2016-09-06 07:49:38 -07:00 committed by Martin Probst
parent 7192fec841
commit aa9b617c9d
3 changed files with 48 additions and 10 deletions

View File

@ -7,7 +7,8 @@
*/ */
import * as common from '@angular/common'; 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'; import {wrapInArray} from './funcs';
@ -51,6 +52,28 @@ export class CompUsingPipes {
export class CompUsingCustomElements { export class CompUsingCustomElements {
} }
@Component({
selector: 'cmp-event',
template: `
<div (click)="handleDomEventVoid($event)"></div>
<div (click)="handleDomEventPreventDefault($event)"></div>
<div (dirEvent)="handleDirEvent($event)"></div>
`,
})
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<string> = new EventEmitter();
}
@NgModule({schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: wrapInArray(CompUsingCustomElements)}) @NgModule({schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: wrapInArray(CompUsingCustomElements)})
export class ModuleUsingCustomElements { export class ModuleUsingCustomElements {
} }

View File

@ -15,18 +15,33 @@ import {MultipleComponentsMyComp, NextComp} from './a/multiple_components';
import {AnimateCmp} from './animate'; import {AnimateCmp} from './animate';
import {BasicComp} from './basic'; import {BasicComp} from './basic';
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components'; 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 {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomePipeInRootModule, SomeService, someLibModuleWithProviders} from './module_fixtures';
import {CompWithNgContent, ProjectingComp} from './projection'; import {CompWithNgContent, ProjectingComp} from './projection';
import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, DirectiveForQuery} from './queries'; import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, DirectiveForQuery} from './queries';
@NgModule({ @NgModule({
declarations: [ declarations: [
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompForChildQuery, SomeDirectiveInRootModule,
CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider, ProjectingComp, SomePipeInRootModule,
CompWithChildQuery, CompWithDirectiveChild, CompWithNgContent, AnimateCmp,
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences, CompUsingPipes, BasicComp,
MultipleComponentsMyComp, DirectiveForQuery, NextComp CompForChildQuery,
CompWithEntryComponents,
CompWithAnalyzeEntryComponentsProvider,
ProjectingComp,
CompWithChildQuery,
CompWithDirectiveChild,
CompWithNgContent,
CompUsingRootModuleDirectiveAndPipe,
CompWithProviders,
CompWithReferences,
CompUsingPipes,
CompConsumingEvents,
DirPublishingEvents,
MultipleComponentsMyComp,
DirectiveForQuery,
NextComp,
], ],
imports: [ imports: [
BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements, BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements,

View File

@ -351,7 +351,7 @@ export abstract class AppView<T> {
} }
} }
eventHandler(cb: Function): Function { return cb; } eventHandler<E, R>(cb: (event?: E) => R): (event?: E) => R { return cb; }
throwDestroyedError(details: string): void { throw new ViewDestroyedError(details); } throwDestroyedError(details: string): void { throw new ViewDestroyedError(details); }
} }
@ -434,9 +434,9 @@ export class DebugAppView<T> extends AppView<T> {
} }
} }
eventHandler(cb: Function): Function { eventHandler<E, R>(cb: (event?: E) => R): (event?: E) => R {
var superHandler = super.eventHandler(cb); var superHandler = super.eventHandler(cb);
return (event: any) => { return (event?: any) => {
this._resetDebug(); this._resetDebug();
try { try {
return superHandler(event); return superHandler(event);