title: Typescript & Knockout.js Math.max computed
body: <p>I'm trying to create a dynamic steps system for a website I'm working on.</p>
  
  <p>It should display current step out of total steps and change current and/or total steps depending on conditions.</p>
  
  <p>e.g.</p>
  
  <p>Step 1/2</p>
  
  <p>Step 2/2</p>
  
  <p>Unfortunately I'm running into a problem I'm not sure how to diagnose because I don't know why it's giving me the error.</p>
  
  <p>The error is:
  "Uncaught TypeError: Cannot read property 'StepNumberOne' of undefined"</p>
  
  <p>Here's my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class ViewModel {
    public IsStepOneActive: KnockoutObservable &lt; boolean &gt; ;
    public IsStepTwoActive: KnockoutObservable &lt; boolean &gt; ;
  
    public StepNumberOne: KnockoutComputed &lt; number &gt; ;
    public StepNumberTwo: KnockoutComputed &lt; number &gt; ;
  
    public Total: KnockoutComputed &lt; number &gt; ;
  
    constructor() {
      this.IsStepOneActive = ko.observable(true);
      this.IsStepTwoActive = ko.observable(false);
  
      this.StepNumberOne = ko.pureComputed(function() {
        if (this.IsStepOneActive()) {
          return 1;
        } else {
          return 0;
        }
      });
  
      this.StepNumberTwo = ko.pureComputed(function() {
        if (this.IsStepTwoActive()) {
          return 2;
        } else {
          return 0;
        }
      });
  
      this.Total = ko.computed(function() {
        return Math.max(this.StepNumberOne(), this.StepNumberTwo);
      });
    }
  }
  
  ko.applyBindings(new ViewModel());</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="target"&gt;
    &lt;div&gt;
      &lt;span data-bind="text: StepNumberOne"&gt;&lt;/span&gt;
      &lt;span&gt; / &lt;/span&gt;
      &lt;span data-bind="text: Total"&gt;&lt;/span&gt;
    &lt;/div&gt;
  
    &lt;div&gt;
      &lt;span data-bind="text: StepNumberTwo"&gt;&lt;/span&gt;
      &lt;span&gt; / &lt;/span&gt;
      &lt;span data-bind="text: Total"&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>