title: How to expose events in typescript so handlers can be defined by ES5 code?
body: <p>I have a TypeScript class that represents a textbox. I want to capture an event when text is changed and the typed text is a bad word and allow other code including ES5 code to handle it.</p>
  
  <pre><code>export class ParentalTextBox {
    private txt : HTMLInputElement;
  
   Attach(textbox : HTMLInputElement) {
      this.txt = textbox;
      this.txt.onchange = () =&gt; CheckForBadWords());
   }
  
   CheckForBadWords() {
    if (this.txt.value == "rascal") {
       // I want to fire an event for any handler to know that a bad word was
       // detected, here.
       //
     }
   }
  }
  </code></pre>
  
  <p>I tried doing something like.</p>
  
  <pre><code> OnBadWordDetected : (word : string, target : HTMLInputElement);
  </code></pre>
  
  <p>but this is giving me an error, I don't want to define it because I want ability for other ES5 users of my class to be able to assign a handler like so</p>
  
  <pre><code>var myobj = new TypeScriptModule.ParentalTextBox();
  myobj.Attach(document.getElementById("searchbox"));
  
  myobj.OnBadWordDetected = function(word, target) {
   alert("I will tell your parents now!");
  }
  </code></pre>
  
  <p>How do I achieve the above?</p>