title: Defining custom events for TypeScript API
body: <p>I am in the process of building the first iteration of an API. One of the things that we need is custom events for whoever is going to use our API. I am having trouble finding good documentation on how to build such things.</p>
  
  <p>We have an interface for our API where I hope to define these custom events.</p>
  
  <pre><code>interface AddinApi{
      /**
      * Event fires when a document is opened.
      *
      * @param   {string}        The url of the of the document you are listening on.
      *   
      * @return  The url of the opened document
      */
      documentOpenedEvent(url: string): void;
  }
  </code></pre>
  
  <p>I know that I am missing something here. Do I need to define some custom object that implements/extends some event class as the parameter?</p>
  
  <p>The desired functionality of this event would be that the user can attach this event to a specific document, and when that document is opened, the event would fire.</p>
  
  <p>This might be called in the following manner. This is more or less pseudo code. </p>
  
  <pre><code>var api : AddinApi;
  
  // Define document object with some url / guid
  var docGUID = "123456;
  
  function onDocumentOpened(url: documentGuid){
     // do something now that the document has been opened
  }
  
  api.documentOpenedEvent = onDocumentOpened;
  
  // Now this function fires off when the document is opened.
  api.documentOpenedEvent(docGuid);
  </code></pre>