Skip to content

feat: add Args.option() for typed arg options#1568

Open
rexxars wants to merge 2 commits intooclif:mainfrom
rexxars:rexxars/typed-arg-options
Open

feat: add Args.option() for typed arg options#1568
rexxars wants to merge 2 commits intooclif:mainfrom
rexxars:rexxars/typed-arg-options

Conversation

@rexxars
Copy link
Copy Markdown
Contributor

@rexxars rexxars commented Mar 30, 2026

Adds a new Args.option() method mirroring Flags.option(), which provides type-safe option usage:

class Deploy extends Command {
  static args = {
    env: Args.option({
      options: ['production', 'staging', 'development'] as const
    })()
  }

  async run() {
    const {args} = await this.parse(Deploy)
    // `args.env` typed as `'production' | 'staging' | 'development' | undefined`
  }
}

Setting it as required removes the undefined from the union.

@rexxars
Copy link
Copy Markdown
Contributor Author

rexxars commented Apr 1, 2026

Updated to include stricter type parsing: I feel it is easy to assume that options like multiple: true would go alongside options, but they should be passed on the second call.

I think theoretically we could make Args.string()/Args.integer() work too, but it would require a lot more typescript overloads - let me know if that is preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant