DefinitelyTyped / DefinitelyTyped/DefinitelyTyped

[@types/yargs] Add support for global options defined outside of CommandModule

Open
#52,069 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
51.4k
Forks
30.4k
Avg merge
3d 21h
Merged PRs (30d)
108

Description

Versions: yargs 16.2.0 and @types/yargs 16.0.1
Definitions by: @poelstra @mizunashi-mana @pushplay @JimiC @steffenvv @forivall @ExE-Boss @Aankhen

CommandModule is a generic type that allows specifying the parameters accepted by the command through the 2nd generic param: CommandModule<unknown, {param1: string}>.

But the typings don't work well with global parameters that have been established outside of the CommandModule in the global Yargs bootstrapping code. Here's an example of a CommandModule, that accepts 1 new param param1, but also passes along a global param globalParam that is defined outside of that module.

image

I tried specifying the global param in the 2nd argument of the CommandModule generic, but then the builder function signature breaks, because it expects the builder to also define that parameter.

Here's my yargs bootstrap code that is located elsewhere:

image

Maybe a third generic argument can be added that supports adding global options that don't need to be accounted for in the builder, but are also passed in to handler?

Contributor guide

No contributing guide indexed for this repository

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 by inspecting the @types/yargs declarations for CommandModule and reproduce the example with yargs 16.2.0 and @types/yargs 16.0.1. The work is done when a command can receive globally defined options in its handler without requiring those options in the builder signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.