title: Export additional interfaces for CommonJS module (Typescript)
body: <p>I'm trying to use a simple JS library in Typescript/React, but am unable to create a definition file for it. The library is google-kgsearch (<a href="https://www.npmjs.com/package/google-kgsearch" rel="noreferrer">https://www.npmjs.com/package/google-kgsearch</a>). It exports a single function in the CommonJS style. I can successfully import and call the function, but can't figure out how to reference the type of the arguments to the result callback.</p>
  
  <p>Here is most of the library code:</p>
  
  <pre><code>function KGSearch (api_key) {
    this.search = (opts, callback) =&gt; {
      ....
      request({ url: api_url, json: true }, (err, res, data) =&gt; {
        if (err) callback(err)
        callback(null, data.itemListElement)
      })
      ....
      return this
    }
  }
  
  module.exports = (api_key) =&gt; {
    if (!api_key || typeof api_key !== 'string') {
      throw Error(`[kgsearch] missing 'api_key' {string} argument`)
    }
  
    return new KGSearch(api_key)
  }
  </code></pre>
  
  <p>And here is my attempt to model it. Most of the interfaces model the results returned by service:</p>
  
  <pre><code>declare module 'google-kgsearch' {
  
      function KGSearch(api: string): KGS.KGS;
      export = KGSearch;
  
      namespace KGS {
  
          export interface SearchOptions {
              query: string,
              types?: Array&lt;string&gt;,
              languages?: Array&lt;string&gt;,
              limit?: number,
              maxDescChars?: number
          }
  
          export interface EntitySearchResult {
              "@type": string,
              result: Result,
              resultScore: number
          }
  
          export interface Result {
              "@id": string,
              name: string,
              "@type": Array&lt;string&gt;,
              image: Image,
              detailedDescription: DetailedDescription,
              url: string
          }
  
          export interface Image {
              contentUrl: string,
              url: string
          }
  
          export interface DetailedDescription {
              articleBody: string,
              url: string,
              license: string
          }
  
          export interface KGS {
              search: (opts: SearchOptions, callback: (err: string, items: Array&lt;EntitySearchResult&gt;) =&gt; void) =&gt; KGS.KGS;
          }
      }
  }
  </code></pre>
  
  <p>My issue is that from another file I am unable to reference the KGS.EntitySearchResult array returned by the search callback. Here is my use of the library:</p>
  
  <pre><code>import KGSearch = require('google-kgsearch');
  const kGraph = KGSearch(API_KEY);
  
  interface State {
      value: string;
      results: Array&lt;KGS.EntitySearchResult&gt;; // &lt;-- Does not work!!
  }
  
  class GKGQuery extends React.Component&lt;Props, object&gt; {    
  
      state : State;
  
      handleSubmit(event: React.FormEvent&lt;HTMLFormElement&gt;) {
          kGraph.search({ query: this.state.value }, (err, items) =&gt; { this.setState({results: items}); });
          event.preventDefault();
      }
      ....
  }
  </code></pre>
  
  <p>Any suggestions for how to make the result interfaces visible to my calling code without messing up the default export is very greatly appreciated.</p>