title: Is there a way to "extract" the type of TypeScript interface property?
body: <p>Let's suppose there's a typing file for library X which includes some interfaces.</p>
  <pre><code>interface I1 {
      x: any;
  }
      
  interface I2 {
      y: {
          a: I1,
          b: I1,
          c: I1
      }
      z: any
  }
  </code></pre>
  <p>In order to work with this library I need pass around an object that is of exactly the same type as <code>I2.y</code>. I can of course create identical interface in my source files:</p>
  <pre><code>interface MyInterface {
      a: I1,
      b: I1,
      c: I1
  }
  
  let myVar: MyInterface;
  </code></pre>
  <p>but then I get the burden of keeping it up to date with the one from library, moreover it can be very large and result in lot of code duplication.</p>
  <p>Therefore, is there any way to &quot;extract&quot; the type of this specific property of the interface? Something similar to <code>let myVar: typeof I2.y</code> (which doesn't work and results in &quot;Cannot find name I2&quot; error).</p>
  <hr />
  <p><strong>Edit</strong>: after playing a bit in TS Playground I noticed that following code achieves exactly what I want to:</p>
  <pre><code>declare var x: I2;
  let y: typeof x.y;
  </code></pre>
  <p>However it requires a redundant variable <code>x</code> to be declared. I am looking for a way to achieve this without that declaration.</p>