title: Typescript React: Access component property types
body: <p>npm package <code>@types/react</code> allows us to use React inside of our TypeScript apps.
  We define components as</p>
  
  <pre><code>type Props = {...}
  
  type State = {...}
  
  export default class MyComponent extends React.Component&lt;Props, State&gt; {
  }
  </code></pre>
  
  <p>here we have to declare types for component props and state (in type variables).</p>
  
  <p>After we declared that types, TypeScript uses that to validate the usage of our component (the shape of props passed to it).</p>
  
  <p>I want to create a container around such a component. The container will reuse the props of the component. But in order to create another component with the same props I have to redeclare the types for props again. Or export them from the original component file and import into container:</p>
  
  <pre><code>// original file
  export type Props = {...}
  
  // container file
  import MyComponent, { Props } from './original'
  </code></pre>
  
  <p>But I'm already importing the <code>MyComponent</code> from that file. This component already contains information about the props it consumes (thanks to type variables in <code>React.Component</code>).</p>
  
  <p>The question is <strong>how do I access that information from the component class itself without explicitly exporting/importing the type for props</strong>?</p>
  
  <p>I want something like:</p>
  
  <pre><code>import MyComponent from './MyComponent'
  
  type Props = MyComponent.Props // &lt;= here access the component prop types
  
  export default class MyContainer extends React.Component&lt;Props, {}&gt; {}
  </code></pre>