title: Extend DefinitelyTyped .d.ts definitions
body: <p>I try to use <a href="https://github.com/segmentio/nightmare" rel="nofollow noreferrer">nightmare</a> in typescript with the types from DefinitelyTyped. however, the types there are incomplete (the <code>then</code> method is missing) and I also want to add dynamically some methods (as it is done in <a href="https://www.npmjs.com/package/nightmare-har-plugin" rel="nofollow noreferrer">this plugin</a>).</p>
  
  <p>I don't understand how to extend the interface of Nightmare without forking DefinitelyTyped. I have read a few pages about these question:</p>
  
  <p><a href="https://stackoverflow.com/questions/32948271/extend-interface-defined-in-d-ts-file">Extend interface defined in .d.ts file</a></p>
  
  <p><a href="http://obaidurrehman.github.io/2015/10/30/extending-typeScript-definitions/" rel="nofollow noreferrer">http://obaidurrehman.github.io/2015/10/30/extending-typeScript-definitions/</a></p>
  
  <p>So I tried to create a <code>extendNightmare.d.ts</code> file that I put along all my other <code>.ts</code> files.</p>
  
  <pre><code>declare namespace Nightmare {
    class Nightmare {
      waitForDevTools(): void;
      then(): Nightmare;
    }
  }
  </code></pre>
  
  <p>At this point, I don't know what to do to tell the compiler to use my new definition that is supposed to extend the existing one.</p>
  
  <p>I tried to add this line at the top of the file using nightmare but it didn't work:</p>
  
  <pre><code>/// &lt;reference path="./extendNightmare.d.ts"/&gt;
  </code></pre>
  
  <p>Also I would like to extend the interface <code>IConstructorOptions</code> from the <code>Nightmare</code> namespace, but I don't know how to do so. Is this correct?</p>
  
  <pre><code>declare namespace Nightmare {
    class Nightmare {
      waitForDevTools(): void;
      then(): Nightmare;
    }
  
    export interface IConstructorOptions {
      switches: any;
    }
  }
  </code></pre>
  
  <p>The code I'm using to reproduce this issue:</p>
  
  <pre><code>/// &lt;reference path="./extendNightmare.d.ts"/&gt;
  
  import * as Nightmare from "nightmare";
  
  const switches = {
    "ignore-certificate-errors": true,
    "proxy-server": "localhost:10000",
  };
  
  function render_page(url) {
    const options = {
      switches,
    };
  
    const nightmare = new Nightmare(options);
  
    nightmare
    .goto(url)
    .then((infos) =&gt; {
      console.info(infos);
    })
    .end()
    .then(() =&gt; {
      console.info(`${url}: done`);
    });
  }
  
  render_page("https://google.com");
  </code></pre>
  
  <p>In my <code>package.json</code>, I have:</p>
  
  <pre><code>"nightmare": "^2.9.1",
  "@types/nightmare": "^1.6.30",
  </code></pre>