diff --git a/lib/yargs-factory.ts b/lib/yargs-factory.ts index 5ef10e8f3..592e678d7 100644 --- a/lib/yargs-factory.ts +++ b/lib/yargs-factory.ts @@ -368,7 +368,7 @@ export class YargsInstance { // This noop tells yargs-parser about the existence of the option // represented by "keys", so that it can apply camel case expansion // if needed: - this.alias(keys, keys); + this.#options.key[keys] = true; this.#globalMiddleware.addCoerceMiddleware( ( argv: Arguments, diff --git a/test/yargs.cjs b/test/yargs.cjs index 7b81729f0..5cf2b700f 100644 --- a/test/yargs.cjs +++ b/test/yargs.cjs @@ -2176,6 +2176,25 @@ describe('yargs dsl tests', () => { yargs().coerce('c'); }, /coerce callback must be provided/); }); + + // Refs: https://github.com/yargs/yargs/issues/1909 + it('shows coerced option in help', async () => { + const help = await yargs() + .option('option1', { + describe: 'option1 description', + type: 'string', + demandOption: true, + }) + .option('option2', { + describe: 'option2 description', + type: 'string', + demandOption: true, + }) + .coerce('option2', () => undefined) + .getHelp(); + console.info(help); + help.should.match(/option2 description/); + }); }); describe('stop parsing', () => {