title: typescript: angular.d.ts defently typed with ng.IPromise
body: <p>I'm getting this ts error while I'm trying to chain ng.IPromise function calls:</p>
  
  <pre><code>Error:(101, 23) TS2345: Argument of type 'IPromise&lt;IResult[]&gt;' is not assignable to parameter of type 'IResult[]'. Property 'length' is missing in type 'IPromise&lt;IResult[]&gt;'.
  </code></pre>
  
  <p>Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public search(stateParams : any, page : any) : ng.IPromise&lt;Array&lt;app.search.entities.IResult&gt;&gt; {
  
   // create promise
   let deferred : ng.IDeferred&lt;Array&lt;app.search.entities.IResult&gt;&gt; = this.$q.defer();
  
   // ensure page is a number
   page = (isNaN(page)) ? 1 : parseInt(page, 10);
  
   // create query
   this.searchServiceSearchQuery.getQuery(
    stateParams,
    this._itemsPerPage,
    (page * this._itemsPerPage) - this._itemsPerPage,
    null
   ).then(
    (query : any) : void =&gt; {
  
     // search
     deferred.resolve(this._search(query)); // &lt;= THIS "this" THROWS THE ERROR ABOVE
  
    }
   );
  
   // return promise
   return deferred.promise;
  
  }
  
  
  private _search(query : any) : ng.IPromise&lt;Array&lt;app.search.entities.IResult&gt;&gt; {
  
  // create deferred
  let deferred : ng.IDeferred&lt;Array&lt;app.search.entities.IResult&gt;&gt; = this.$q.defer();
  
  // run query
  this.coreServiceRestangularHelpmeSearch
   .one('search')
   .get({q : query})
   .then(
    (data : any) : void =&gt; {
  
     // found results
     if (
      data !== null &amp;&amp;
      'results' in data === true
     ) {
  
      // create entities
      let entities : Array&lt;app.search.entities.IResult&gt; = [];
  
      // walk through all results
      data.results.forEach((result : any) : void =&gt; {
  
       // create entity
       let entity : app.search.entities.IResult = new app.search.entities.Result(
        result.id,
        result.cat1Ids[0],
        result.cat2Ids[0],
        result.cat3Ids[0],
        result.typeCode,
        (result.sort)    ? parseInt(result.sort, 10) : null,
        result.title,
        result.description,
        this.$sce.trustAsHtml(result.summary),
        false
       );
  
       entities.push(entity);
  
      });
  
      // sort all by sort key
      entities.sort(
       (
        a : app.search.entities.IResult,
        b : app.search.entities.IResult
       ) : number =&gt; {
  
        if (a.getSortKey() &gt; b.getSortKey()) {
  
         return 1;
  
        } else if (a.getSortKey() &lt; b.getSortKey()) {
  
         return -1;
  
        }
  
        return 1;
  
       }
  
      );
  
      deferred.resolve(this._extendResults(entities));
  
     }
  
     // return empty object
     deferred.reject('invalid api response');
  
    },
    () : any =&gt;  {
  
     deferred.reject('failed to fetch search results');
  
    }
  
   )
  
  ;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Do I do something wrong or is there an issue with the def-typed file? If I change the generic of the <code>_search()</code> function to <code>any</code>, everything looks fine.</p>