title: Angular: Correct way to define custom type/model for object that can contain many different properties?
body: <p><strong>My goal is to use TypeScript to enhance the readability of my current code base</strong>. I've realized in many Services &amp; Components I am ending up with a lot of code that has parameters types and return types of <code>any</code>. </p>
  
  <p>For example something like the code below, but with many more functions.</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  
  @Injectable()
  export class ExampleService {
  
    private someFuncA(objA: any): void {
      // Do some work
    } 
    private someFunB(objA: any): any {
      // Do some work
    }
    private someFunC(objB: any): string {
      // Do some work
    }
  }
  </code></pre>
  
  <p>The problem is <code>objA</code> is a really large object that can have hundreds of properties. Sometimes those properties are present and sometimes they are not. <strong>The objects are coming from the Server and I do not have the ability to change them.</strong></p>
  
  <p>What I would like to do is change the <code>any</code> types to something meaningful so the code is more easily read. For example like the following code:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  
  @Injectable()
  export class ExampleService {
  
    private someFuncA(objA: SeismicData): void {
      // Do some work
    } 
    private someFunB(objA: SeismicData): SeismicData {
      // Do some work
    }
    private someFunC(objB: ReflectiveData): number {
      // Do some work
    }
  }
  </code></pre>
  
  <p>I know I can't use any interface, because the structure of the objects are so dynamic. Properties can exist in one instance and not in another. I am not sure if it makes sense to create a model that is just blank for example:</p>
  
  <pre><code>export class SeismicData {}
  </code></pre>
  
  <p>However, I do not feel that is the best/correct practice and hope that someone in the community can guide me in the right direction on how to handle a use case like this.</p>