title: Typescript - TypeError myclass.myFunction is not a function
body: <p>I'm facing an issue with the following code. </p>
  
  <p>What it basically should do. It should load and parse a given JSON file. And in the RequestListender it should show the <code>ID</code> and the string <code>Hello</code> which is returned by the <code>ToString()</code> method in <em>Product.ts</em>. Where the <code>tProduct.Id</code> is shows up correctly, the <code>tProduct.ToString()</code> method fails with the error stated below.</p>
  
  <p>Thanks a lot in advance.</p>
  
  <p><em>Error message:</em></p>
  
  <pre><code>TypeError: tProduct.ToString is not a function. 
   (In 'tProduct.ToString()', 'tProduct.ToString' is undefined)
  </code></pre>
  
  <p><em>File: Test.ts</em></p>
  
  <pre><code>var currentProduct = null as pvis.Product;
  
  function runTest(path) {
      var request = new XMLHttpRequest();
      request.onload = loadRequestListener;
      request.open("get", path, true);
      request.send();
  }
  
  function loadRequestListener () {
      var tProduct : pvis.Product = JSON.parse(this.responseText);
      if (tProduct.Id) {
          currentProduct = tProduct;
          alert('loaded with Id: ' + tProduct.Id );   
          alert('loaded with Content: ' + tProduct.ToString() );  
      }
      else {
          alert('product failed to load');
      }
  
  }
  </code></pre>
  
  <p><em>File Product.ts</em></p>
  
  <pre><code>module pvis {
      export class Product {
  
          Id: string;
  
          ToString():string {
              return 'Hello';
          }
      }
  }
  </code></pre>
  
  <p><em>The HTML part:</em></p>
  
  <pre><code>&lt;body onload="runTest('assets/products/json/A379N.json')"&gt;
  </code></pre>
  
  <p><em>The compiled Javascript:</em></p>
  
  <pre><code>var pvis;
  (function (pvis) {
      var Product = (function () {
          function Product() {
          }
          Product.prototype.ToString = function () {
              return 'Hello';
          };
          return Product;
      })();
      pvis.Product = Product;
  })(pvis || (pvis = {}));
  var currentProduct = null;
  function runTest(path) {
      var request = new XMLHttpRequest();
      request.onload = loadRequestListener;
      request.open("get", path, true);
      request.send();
  }
  function loadRequestListener() {
      var tProduct = JSON.parse(this.responseText);
      if (tProduct.Id) {
          currentProduct = tProduct;
          alert('loaded with Id: ' + tProduct.Id);
          alert('loaded with Content: ' + tProduct.ToString());
      }
      else {
          alert('product failed to load');
      }
  }
  </code></pre>
  
  <p><em>The tsconfig.json (I'm not sure if it is relevant):</em> </p>
  
  <pre><code>{
      "compilerOptions": {
          "target": "ES5",
          "removeComments": true,
          "preserveConstEnums": true,
          "out": "js/main.js",
          "sourceMap": true
      },
      "files": [
         "src/Test.ts"
      ]
  }
  </code></pre>