I know this topic is old but I had a lot of trouble finding help with it. I solved it, but I am not yet fluent in either Typescript or JavaScript, and would like some feedback.
After reading the answers above I could not figure out where the type ICommand was located. However I did find a type name Command.
Furthermore the various snippets use inconsistent variable names which made them difficult to decipher.
So I played around a while and came up with this complete example. The entire app is in one file:
import commander = require('commander');
interface InterfaceCLI extends commander.Command {
user?: string
password?: string
}
class Startup {
public static main(): number {
const cli: InterfaceCLI = commander
.option('-u, --user [user]', 'user id')
.option('-p, --password [password]', 'user\'s password')
.parse(process.argv);
console.log(cli.user, cli.password);
return 0;
}
}
Startup.main();
Dependencies: install commander@2.16.0 --save
Please let me know what you think of this solution as I intend to use it as the starting point of a production command line application.