简体   繁体   English

Yarg() function 的类型 output 是什么?

[英]What is the typed output of the Yarg() function?

I've been making a CLI and i needed yargs for parsing my arguments in a nice way.我一直在制作一个 CLI,我需要 yargs 来以一种很好的方式解析我的 arguments。 I am using typescript and i don't know the output of this Function, didn't find it anywhere as well:我正在使用 typescript 并且我不知道这个 Function 的 output,也没有在任何地方找到它:

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.argv设置为any不是一个选项。 I guess extending from the base interface like this:我想像这样从基本接口扩展:

interface yargs_config extends Yargs.Argv<{}> {
  bots: number;
}

The Type casting at the end fixed my Problem thanks @Thomas Sablik最后的类型转换解决了我的问题感谢@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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM