{"id":14155868,"url":"https://github.com/commander-js/extra-typings","last_synced_at":"2026-05-29T12:01:08.676Z","repository":{"id":56730157,"uuid":"524291261","full_name":"commander-js/extra-typings","owner":"commander-js","description":"Infer strong typings for commander options and action handlers","archived":false,"fork":false,"pushed_at":"2026-05-24T21:24:42.000Z","size":531,"stargazers_count":123,"open_issues_count":1,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-05-24T23:24:06.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/commander-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["shadowspawn","abetomo","tj"],"tidelift":"npm/commander"}},"created_at":"2022-08-13T03:38:46.000Z","updated_at":"2026-05-10T11:19:16.000Z","dependencies_parsed_at":"2024-05-11T06:20:49.076Z","dependency_job_id":"f8867f2e-36d6-42e3-86ac-7fe04a26003e","html_url":"https://github.com/commander-js/extra-typings","commit_stats":{"total_commits":95,"total_committers":6,"mean_commits":"15.833333333333334","dds":"0.052631578947368474","last_synced_commit":"e53229bf91e73df4a1b5b6be3ef39b1737397b63"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/commander-js/extra-typings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commander-js%2Fextra-typings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commander-js%2Fextra-typings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commander-js%2Fextra-typings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commander-js%2Fextra-typings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commander-js","download_url":"https://codeload.github.com/commander-js/extra-typings/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commander-js%2Fextra-typings/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33650712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-17T08:05:03.436Z","updated_at":"2026-05-29T12:01:08.664Z","avatar_url":"https://github.com/commander-js.png","language":"TypeScript","funding_links":["https://github.com/sponsors/shadowspawn","https://github.com/sponsors/abetomo","https://github.com/sponsors/tj","https://tidelift.com/funding/github/npm/commander"],"categories":["others"],"sub_categories":[],"readme":"# extra-typings for commander\n\n[![NPM Version](http://img.shields.io/npm/v/@commander-js/extra-typings.svg?style=flat)](https://www.npmjs.org/package/@commander-js/extra-typings)\n[![NPM Downloads](https://img.shields.io/npm/dm/@commander-js/extra-typings.svg?style=flat)](https://npmcharts.com/compare/@commander-js/extra-typings?minimal=true)\n\nThis package offers TypeScript typings for `commander` which infer strong types for:\n\n- all the parameters of the action handler, including the options\n- options returned by `.opts()`\n\nThis package requires TypeScript 5.0 or higher.\n\nThe runtime is supplied by commander. This package is all about the typings.\n\nUsage\n\n- install `@commander-js/extra-typings` using your preferred package manager\n- install `commander`, if not already installed (peer dependency)\n- in code import from `@commander-js/extra-typings` instead of `commander` (or set up an ambient module)\n\nThe installed version of this package should match the major and minor version numbers of the installed commander package, but the patch version number is independent (following pattern used by [Definitely Typed](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library)).\n\nCredit: this builds on work by @PaperStrike in \u003chttps://github.com/tj/commander.js/pull/1758\u003e\n\n## Limitations\n\n- the generics lead to some noisy types visible in editor and errors\n- some minor code changes required for subclasses of `Command`, `Argument`, or `Option` (see [subclass.test-d.ts](./tests/subclass.test-d.ts))\n  - chaining methods which do type inference return base class rather than `this`\n  - subclass of `Command` returns base class not subclass from `.command(name)`\n  - type parameter needed for class declaration of subclass of `Option` and `Argument`\n\n## Usage tips\n\nThe 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.\n\n```typescript\nimport { program } from '@commander-js/extra-typings';\n\nprogram.command('print')\n  .argument('\u003cfile\u003e')\n  .option('--double-sided')\n  .action((targetFile, options) =\u003e {\n    // command-arguments and options are fully typed\n  });\n```\n\nFor working with a single command without an action handler, the configuration need to be done at the same time as the variable is declared.\n\n```typescript\nimport { Command } from '@commander-js/extra-typings';\n\n// broken pattern\nconst program = new Command(); // program type does not include options or arguments\nprogram.option('-d, --debug'); // adding option does not change type of program\nconst options = program.opts(); // dumb type\n```\n\n```typescript\nimport { Command } from '@commander-js/extra-typings';\n\n// working pattern\nconst program = new Command()\n  .option('-d, --debug'); // program type includes chained options and arguments\nconst options = program.opts(); // smart type\n```\n\n## Ambient module setup\n\nAn alternative approach is to setup `@commander-js/extra-typings` as an ambient module and a development-only dependency.\n\nAdd a simple ambient module file to your project to use the enhanced typings instead of the default typings:\n\n```typescript\n// commander.d.ts\ndeclare module \"commander\" {\n  export * from \"@commander-js/extra-typings\";\n}\n```\n\nImport from `commander` as usual and you hopefully get the extra typings from the ambient module without needing `extra-typings` at runtime:\n\n```typescript\nimport { Command } from 'commander';\nconst program = new Command()\n  .option('-d, --debug');\nconst options = program.opts(); // smart type\n```\n\n## Support\n\nThe current version of `@commander-js/extra-typings` is fully supported on Long Term Support versions of Node.js, and requires at least v22.12.0.\n\nOlder major versions receive security updates for 12 months. For more see: [Release Policy](./docs/release-policy.md).\n\nThe main forum for free and community support is the project [Issues](https://github.com/commander-js/extra-typings/issues) on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommander-js%2Fextra-typings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommander-js%2Fextra-typings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommander-js%2Fextra-typings/lists"}