0

I've been making a CLI and i needed yargs for parsing my arguments in a nice way. I am using typescript and i don't know the output of this Function, didn't find it anywhere as well:

const argv = Yargs(hideBin(process.argv))
  .command('serve', 'Start the Bots.', (yargs: Argv) => {
    return yargs.option('bots', {
      alias: 'b',
      describe: 'Number of bots to create',
      type: 'number',
      default: 10,
      demand: 'Amount is required!',
    });
  })
  .parse();

Setting the argv to any is not a option. I guess extending from the base interface like this:

interface yargs_config extends Yargs.Argv<{}> {
  bots: number;
}
jauki
  • 73
  • 6

1 Answers1

-1

The Type casting at the end fixed my Problem thanks @Thomas Sablik


interface BotArguments extends Arguments {
  bots: number;
}

const botService = new BotService();
const argv = await Yargs(hideBin(process.argv))
  .command('serve', 'Start the Bots.', (yargs: Argv) => {
    return yargs.option('bots', {
      alias: 'b',
      describe: 'Number of bots to create',
      type: 'number',
      default: 10,
      demand: 'Amount is required!',
    });
  })
  .parse();
const bots = (argv as BotArguments).bots;
jauki
  • 73
  • 6