Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 552 Bytes

functions.md

File metadata and controls

28 lines (21 loc) · 552 Bytes

Functions

Event Handlers

  • Type the event handler, not the callback.

    Why? Provides better code completion. This can be removed when microsoft/TypeScript#8134 lands.

    // Bad
    export interface MyEventCallback {
      (event: { ... }): void;
    }
    
    export interface ABC {
      onMyEvent(callback: MyEventCallback): Disposable;
    }
    
    // Good
    export interface MyEventHandler {
      (callback: (event: { ... }) => void): Disposable;
    }
    
    export interface ABC {
      onMyEvent: MyEventHandler;
    }