title: Typescript check if object matches type
body: <p>I have the following problem. Let's say I have a type:</p>
  
  <pre><code>type A = {
      prop1: string,
      prop2: {
          prop3: string
      }
  }
  </code></pre>
  
  <p>I am receiving some json object from an external service and I want to validate if that json matches type <code>A</code>:</p>
  
  <pre><code>function isA(obj:any): boolean {
      // What should be here?
  }
  </code></pre>
  
  <p>So if my <code>obj</code> is something like:</p>
  
  <pre><code>{
   prop1: "Hello",
   prop2: {
      prop3: "World"
   }
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>{
       prop1: "Hello",
       prop2: {
          prop3: "World"
       },
       moreProps: "I don't care about"
  }
  </code></pre>
  
  <p>The function would return true, but false for something like</p>
  
  <pre><code>{
       foo: "Hello",
       bar: {
          prop3: "World"
       }
  }
  </code></pre>
  
  <p>What's the easiest way to achieve this?</p>
  
  <p>Thanks.</p>