Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Yargs Command Typing #79

Open
4 tasks
ChristopherPHolder opened this issue Jan 29, 2024 · 0 comments
Open
4 tasks

Improve Yargs Command Typing #79

ChristopherPHolder opened this issue Jan 29, 2024 · 0 comments

Comments

@ChristopherPHolder
Copy link
Owner

Description

Main currently looks like this:

const argv = await yargs(hideBin(process.argv))
  .options({ verbose, help, shutdown, dryRun })
  .command([ userFlowCommand ])
  .parse();

This means that all the commands have a default set of options.

However, the command typing is incorrect:

type UserFlowCommand = CommandModule<NonNullable<unknown>, UserFlowCommandOptions>

As it should include the global types in the command generict type.


We are also incorrectly declarring the command modules in yargs as we pass it as a command array and it propably should not be, eg: .command([ userFlowCommand ]).


We are also incorrectly using the Command builder

const userFlowBuilder: CommandBuilder = { queue, store };

This should be using the proper (argv) => argv.options(...options) with its correct typing.


We are also incorrectly using the type declarations of the command arguments. We should use the yargs typing that inferres it insead of creating out own interface!

TODOS

  • Fix command module typing to include generics of options
  • Fix command declaration to not be array of commands
  • Use typed functional command builders
  • Use InferredOptionTypes instead of our own interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant