title: Use commander in typescript
body: <p>I try to use commander in typescript and I could like to give a proper type to my cli. So I start with this code:</p>
  
  <pre><code>import * as program from "commander";
  
  const cli = program
    .version("1.0.0")
    .usage("[options]")
    .option("-d, --debug", "activate more debug messages. Can be set by env var DEBUG.", false)
    .parse(process.argv);
  
  console.log(cli.debug)
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>example.ts(9,17): error TS2339: Property 'debug' does not exist on type 'Command'.
  </code></pre>
  
  <p>So I tried to add an interface, as documented <a href="https://stackoverflow.com/questions/37199787/how-can-i-use-commander-npm-with-typescript">here</a>:</p>
  
  <pre><code>import * as program from "commander";
  
  interface InterfaceCLI extends commander.Command {
    debug?: boolean;
  }
  
  const cli: InterfaceCLI = program
    .version("1.0.0")
    .usage("[options]")
    .option("-d, --debug", "activate more debug messages. Can be set by env var DEBUG.", false)
    .parse(process.argv);
  
  console.log(cli.debug)
  </code></pre>
  
  <p>and I get this error:</p>
  
  <pre><code>example.ts(3,32): error TS2503: Cannot find namespace 'commander'.
  </code></pre>
  
  <p>From what I understand, <code>cli</code> is actually a class of type <code>commander.Command</code> So I tried to add a class:</p>
  
  <pre><code>import * as program from "commander";
  
  class Cli extends program.Command {
      public debug: boolean;
  }
  
  const cli: Cli = program
    .version("1.0.0")
    .usage("[options]")
    .option("-d, --debug", "activate more debug messages. Can be set by env var DEBUG.", false)
    .parse(process.argv);
  
  console.log(cli.debug)
  </code></pre>
  
  <p>Which gives me this error:</p>
  
  <pre><code>example.ts(7,7): error TS2322: Type 'Command' is not assignable to type 'Cli'.
    Property 'debug' is missing in type 'Command'.
  </code></pre>
  
  <p>I don't know how to add a property to the <code>Command</code> class, either in my file or in a new .d.ts file.</p>