title: Can Angular `HttpClient` `.get()` generics have non-simple property types? (e.g. other than `string` or `number`)
body: <p>I've burned a day researching the subject, and I haven't found any clues.  All I have found is <em>omission</em>, in that nothing I've read states that you <em>can</em> use non-simple types (by which I mean <code>string</code> and <code>number</code>) for the generic interface ("shape") when calling an Angular 4.4 <code>HttpClient.&lt;T&gt;get()</code>.</p>
  
  <p>Rather than fail to describe the problem, the following example code is what I'm trying to do:</p>
  
  <pre><code>// Injected in my real code ... but these are the libs being used.
  import { HttpClientModule } from '@angular/common/http';
  import { Observable } from "rxjs";
  import 'rxjs/Rx';
  
  interface IMyDataItem {
      // In this example, using @Types/Decimal.js
      // It appears the "problem" exists for any types beside the simples (number/string etc)
      results: decimal.Decimal[];
  }
  
  class Service {
     doSomethingCool() {
         this._http
            .get&lt;IMyDataItem&gt;("url://somewhere")
            .subscribe(
               data =&gt; {
                  // Call a method on the Decimal typed property
                  data.results[0].pow(3, 3);
               }
            );
     }
  }
  </code></pre>
  
  <p>Syntactically it compiles.  TypeScript correctly resolves the generic magic - and recognises that <code>data.results</code> is an array of type <code>Decimal</code>.</p>
  
  <p>However in run-time (in Chrome, after transpiling to Javascript) the call to <code>pow()</code> fails, citing that the method does not exist (and indeed, debugging it shows that it is a plain old Javascript object).</p>
  
  <p>I'm very new to TypeScript and Angular 4 - but this feels logical to me.  I've only asked the generic <code>get()</code> call to process the request as an interface.  It's had to determine how to construct an object that fulfills that interface.  Nowhere have I constructed a solid object which implements that interface, and nowhere have I constructed a <code>Decimal</code>.</p>
  
  <p>(Update: This article further leads me to believe my gut... <a href="https://jameshenry.blog/typescript-classes-vs-interfaces/" rel="nofollow noreferrer">https://jameshenry.blog/typescript-classes-vs-interfaces/</a>)</p>
  
  <p>The <a href="https://angular.io/guide/http#typechecking-the-response" rel="nofollow noreferrer">official documentation</a> (and indeed every non-official source I've observed) demonstrates it working with (in my terms) "simple" types (specifically <code>number</code> and <code>string</code>) - which my gut says "makes sense" because a <code>JSON</code> object can have simple strings and simple numbers.</p>
  
  <p>Am I missing the obvious?  Or is it just impossible to directly map to more complex class types?</p>
  
  <p>If it is impossible - how do you normally go about handling it?  I've looked for "best practice" patterns - and come up short.</p>
  
  <p>Again, my gut (and it is only <em>my gut</em> says I should have a private method inside a class which deals with API requests - and returns an <code>Observable</code> (to which the caller will subscribe) which gives a complex object type (e.g. an array of <code>User</code> classes, which have user-related methods on them):</p>
  
  <pre><code>class Service {
     // Return a complex object type Observable for consumption elsewhere
     doSomethingCool(): Observable&lt;IMyDataItem&gt; {
         return this._http
            .get&lt;IMyDataItem&gt;("url://somewhere");
     }
  }
  </code></pre>
  
  <p>Does that make sense?  TIA.</p>