BrunoLM BrunoLM - 2 months ago 17x
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?


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 :