BrunoLM BrunoLM - 1 year ago 345
Node.js Question

How can I use commander (npm) with TypeScript?

I have the following code on my app:

import commander = require('commander');

.option('-u, --user [user]', 'user code')
.option('-p, --pass [pass]', 'pass code')

Then I try to access:


But I get an error (commander.d.ts from DefinitelyTyped):

user does not exist on type IExportedCommand

I tried adding this

interface IExportedCommand {
user: string;
pass: string;

But I still get the error. How can I fix this?

Answer Source

Create a file commander-expansion.d.ts with the following :

declare namespace commander {
    interface IExportedCommand extends ICommand {
        user: string; 
        pass: string;


Because I did something like this recently, recommend --auth user:password. Saves you dealing with user missing username or password. But prevents using : as a password property


More :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download