title: Custom Knockout Validation Rules with TypeScript
body: <p>This is very similar to another question I have active, but may as well ask it as its different and may be found useful by a different audience.</p>
  
  <p>I have a custom rule for knockout validation:</p>
  
  <pre><code>ko.validation.rules["sameAs"] = {
      validator: function (val, otherObservable) {
          return val === otherObservable();
      },
      message: "Value should be same as {0}, but differs"
  };
  </code></pre>
  
  <p>Now in raw javascript this worked fine as the usage would look like:</p>
  
  <pre><code>function SomeObject() {
     this.Email = ko.observable().extend({ required: true, email: true });
     this.ConfirmationEmail = ko.observable().extend({ required: true, email: true, sameAs: this.Email });
  }
  </code></pre>
  
  <p>However now in Typescript land if I try to write this:</p>
  
  <pre><code>class SomeObject {
     public Email = ko.observable().extend({ required: true, email: true });
     public ConfirmationEmail = ko.observable().extend({ required: true, email: true, sameAs: this.Email });
  }
  </code></pre>
  
  <p>I now get the error:</p>
  
  <blockquote>
    <p>Keyword 'this' cannot be referenced in initializers in a class body,
    or in super constructor calls</p>
  </blockquote>
  
  <p>Which makes sense, however I am not sure how I can do what I would originally have done, unless I try to hack it into the constructor or something, which makes my classes now look a bit ghastly.</p>