title: Error TS2497: Module '...' resolves to a non-module entity and cannot be imported using this construct
body: <p>Given this declaration file <code>promise-retry/index.d.ts</code>, which follows TypeScript's official <a href="https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html" rel="nofollow noreferrer">module-function.d.ts</a> format:</p>
  
  <p><strong>Edit:</strong> <em>pasted the wrong code segment for this previously (which is still visible below)</em>:</p>
  
  <pre><code>export = promiseRetry;
  
  declare function promiseRetry(options: Partial&lt;PromiseRetry.NodeRetryOptions&gt;, fn: (retry: PromiseRetry.RetryFn, attempt: number) =&gt; Promise&lt;any&gt;): Promise&lt;any&gt;;
  declare function promiseRetry(fn: (retry: PromiseRetry.RetryFn, attempt: number) =&gt; Promise&lt;any&gt;, options ?: Partial&lt;PromiseRetry.NodeRetryOptions&gt;): Promise&lt;any&gt;;
  
  declare namespace PromiseRetry {
      export interface NodeRetryOptions {
          forever: boolean;
          unref: boolean;
          retries: number;
          factor: number;
          minTimeout: number;
          maxTimeout: number;
          randomize: number | false;
      }
  
      export type RetryFn = (err: any) =&gt; never;
  }
  </code></pre>
  
  <p>I find I cannot import <code>NodeRetryOptions</code> nor <code>RetryFn</code> via this syntax:</p>
  
  <pre><code>import {NodeRetryOptions, RetryFn} from "promise-retry";
  
  let options: NodeRetryOptions = { forever: false };
  let retryFn: RetryFn = (err:any)=&gt;{throw "Nobody responds on StackOverflow"};
  </code></pre>
  
  <p>... as it throws the compile error: <code>error TS2497: Module '"promise-retry"' resolves to a non-module entity and cannot be imported using this construct.</code></p>
  
  <p>I also tried another syntax:</p>
  
  <pre><code>declare module "promise-retry" {
      export = promiseRetry;
  
      function promiseRetry(options: Partial&lt;PromiseRetry.NodeRetryOptions&gt;, fn: (retry: PromiseRetry.RetryFn, attempt: number) =&gt; Promise&lt;any&gt;): Promise&lt;any&gt;;
      function promiseRetry(fn: (retry: PromiseRetry.RetryFn, attempt: number) =&gt; Promise&lt;any&gt;, options ?: Partial&lt;PromiseRetry.NodeRetryOptions&gt;): Promise&lt;any&gt;;
  
      namespace PromiseRetry {
          export interface NodeRetryOptions {
              forever: boolean;
              unref: boolean;
              retries: number;
              factor: number;
              minTimeout: number;
              maxTimeout: number;
              randomize: number | false;
          }
  
          export type RetryFn = (err: any) =&gt; never;
      }
  }
  </code></pre>
  
  <p>But the imports (in a different style) failed too:</p>
  
  <pre><code>import * as PromiseRetry from "promise-retry";
  
  let options: PromiseRetry.NodeRetryOptions = { forever: false };
  let retryFn: PromiseRetry.RetryFn = (err:any)=&gt;{throw "Nobody responds on StackOverflow"};
  </code></pre>
  
  <p>... throwing the very same compiler error.</p>
  
  <p>I've read everything I can find (including the related links here), and I can't get it working. In the words of Trump, "Nobody knew TypeScript imports could be so complicated."</p>