Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@commander-js/extra-typings
Advanced tools
Infer strong typings for commander options and action handlers
This package offers experimental TypeScript typings for commander
which infer strong types for:
.opts()
Limitations
Command
, Argument
, or Option
Usage
@commander-js/extra-typings
using your preferred package managercommander
, if not already installed (peer dependency)@commander-js/extra-typings
instead of commander
The runtime is supplied by commander. This package is all about the typings.
Credit: this builds on work by @PaperStrike in https://github.com/tj/commander.js/pull/1758
The types are built up as the options and arguments are defined. The usage pattern for action handlers is easy. Just chain the action handler after the options and arguments.
program.command('print')
.argument('<file>')
.option('--double-sided')
.action((targetFile, options) => {
// targetFile and options are fully typed
});
For working with a single command without an action handler, the configuration need to be done at the same time as the variable is declared.
// broken pattern
const program = new Command(); // program type does not include options or arguments
program.option('-d, --debug'); // adding option does not change type of program
const options = program.opts(); // dumb type
// working pattern
const program = new Command()
.option('-d, --debug'); // program type includes chained options and arguments
const options = program.opts(); // smart type
0.1.0 (2022-08-16)
.argument()
.arguments()
.addArgument()
.command()
.option()
.addOption()
.action()
.opts()
FAQs
Infer strong typings for commander options and action handlers
The npm package @commander-js/extra-typings receives a total of 375,028 weekly downloads. As such, @commander-js/extra-typings popularity was classified as popular.
We found that @commander-js/extra-typings demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.