When attempting to utilize yargs for command line parsing in typescript, I encountered an issue:
import yargs from 'yargs';
const argv = yargs
.option('label', {
alias: 'l',
describe: 'Execute bot with these labels',
demandOption: false,
type: 'string',
})
.option('console', {
alias: 'c',
describe: 'Log to console',
demandOption: false,
type: 'boolean',
})
.help()
.alias('help', 'h')
.argv;
if(argv.label){
console.log('label');
}
An error is generated by the compiler:
Property 'label' does not exist on type '{ [x: string]: unknown; label: string | undefined; console: boolean | undefined; _: (string | number)[]; $0: string; } | Promise<{ [x: string]: unknown; label: string | undefined; console: boolean | undefined; _: (string | number)[]; $0: string; }>'.
Property 'label' does not exist on type 'Promise<{ [x: string]: unknown; label: string | undefined; console: boolean | undefined; _: (string | number)[]; $0: string; }>'