title: Iterate an array of class in Promise written using TypeScript and TypeCast Generics
body: <p>I have the below code in OO.ts file :</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>import * as $ from "jquery";
          interface ValidatableInterface {
      isValid() : boolean;
  }
  
  class User implements ValidatableInterface {
      /*public name: string;
      public password: string;*/
  
      constructor(public name:string, public password:string) {
      }
  
      getString() {
          return `${this.name} -&gt; ${this.password}`;
      }
  
      isValid() : boolean {
          return true;
      }
  }
  
          class GenericRepository&lt;T extends ValidatableInterface&gt; {
      private _url : string;
      constructor(url : string) {
          this._url = url;
      }
  
      public getAsync() {
          return new Promise((resolve: (entities: T[]) =&gt; void, reject) =&gt; {
              $.ajax({
                  url: this._url,
                  type: "GET",
                  dataType: "json",
                  success: (data) =&gt; {
                      let list : T[];
                      let items = &lt;T[]&gt;data.items;
                      for(let i = 0; i &lt; items.length; i++) {
                          if(&lt;T&gt;&lt;any&gt;items[i].isValid()) {
                              list.push(items[i]);
                          }
                      }
                      resolve(list);
                  },
                  error: (e) =&gt; {
                      reject(e);
                  }
              })
          })
      }
  }
  
          export {
          User,
          GenericRepository
          }</code></pre>
  </div>
  </div>
  </p>
  
  
  
  <p>In app.ts i am have the below 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>import { User, GenericRepository } from './OO';
  
  let userRepository = new GenericRepository&lt;User&gt;('./shared/users.json');
  userRepository.getAsync()
      .then((users: User[])=&gt; {
          console.log(`User Repository =&gt;`);
          /*
          Not working either
          users.forEach(function(user) {
              console.log(user.getString());
          });*/
          for(let i = 0; i &lt; users.length; i++) {
              console.log(users[i].getString());
          }
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I try to iterate the user array (Array of user class) the error I am seeing is Uncaught (in promise) TypeError: e[t].getString is not a function and In the forEach the error I am seeing is Uncaught (in promise) TypeError: e.getString is not a function.</p>
  
  <p>I am unable to typecast : The error I am now getting is Uncaught TypeError: n[r].isValid is not a function</p>
  
  <p>Can anybody explain what is this error.</p>
  
  <p>Thanks in advance</p>