yargs / yargs/yargs

Nested object options and TypeScript aren't compatible

Open
#2,137 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
11.5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Using object options

If I want to pass object options, like tool --bq.project=zzz
then how should I describe the option?

I tried as

        .option(
            'bq.project',
            {type: 'string', description: 'GCP project id for BigQuery'})

but in TypeScript it doesn't work.
I do see intellisence for argv['bq.project'] but it's not correct (it returns undefined), the correct call is argv.bg.project, but in TypeScript is not legal, because argv has no 'bq' field.
Of cause with the casting (<any>argv.bq).project it works, but it's ugly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docs/tricks.md's object-options guidance and reproduce the bq.project example from the issue. Inspect how the option declaration and argv access are typed; done means nested object options have accurate TypeScript access without an any cast.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
cli, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.