🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@commander-js/extra-typings

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commander-js/extra-typings - npm Package Compare versions

Comparing version
14.0.0
to
15.0.0
+34
-14
index.d.ts

@@ -35,2 +35,18 @@ // eslint complains about {} as a type, but hard to be more accurate.

// Allowed default value type based on whether the option takes an argument.
// Required variadic <value...>: string[] only.
// Optional variadic [value...]: string[] or boolean (flag-only use returns true as preset).
// Required non-variadic <value>: string only.
// Optional non-variadic [value]: string or boolean (flag-only use returns true as preset).
// Boolean flags (no argument): boolean only.
type AllowedDefaultType<S extends string> = S extends `${string} <${string}...>`
? string[]
: S extends `${string} [${string}...]`
? string[] | boolean
: S extends `${string} <${string}>`
? string
: S extends `${string} [${string}]`
? string | boolean
: boolean;
type InferArgumentType<Value extends string, DefaultT, CoerceT, ChoicesT> = [

@@ -218,10 +234,17 @@ CoerceT,

? Name extends keyof Options
? InferOptionsCombine<Options, Name, PresetT, true> // combo does not set default, leave that to positive option
? InferOptionsCombine<Options, Name, PresetT, true> // negated option does not set default (true) in combo
: InferOptionsCombine<Options, Name, PresetT | DefaultT, true> // lone negated option sets default
: InferOptionsCombine<
Options,
Name,
ValueT | PresetT | DefaultT,
AlwaysDefined
>;
: Name extends keyof Options
? InferOptionsCombine<
Omit<Options, Name>, // remove earlier negated option which probably had implied `true` (see NegateDefaultType), add back without `true`
Name,
Exclude<Options[Name], true> | ValueT | PresetT | DefaultT,
AlwaysDefined
>
: InferOptionsCombine<
Options,
Name,
ValueT | PresetT | DefaultT,
AlwaysDefined
>;

@@ -1036,3 +1059,3 @@ // Recalc values taking into account negated option.

>;
option<S extends string, DefaultT extends string | boolean | string[] | []>(
option<S extends string, DefaultT extends AllowedDefaultType<S>>(
usage: S,

@@ -1072,6 +1095,3 @@ description?: string,

>;
requiredOption<
S extends string,
DefaultT extends string | boolean | string[],
>(
requiredOption<S extends string, DefaultT extends AllowedDefaultType<S>>(
usage: S,

@@ -1468,3 +1488,3 @@ description?: string,

/** @deprecated since v7 */
outputHelp(cb?: (str: string) => string): void;
outputHelp(cb: (str: string) => string): void;

@@ -1496,3 +1516,3 @@ /**

/** @deprecated since v7 */
help(cb?: (str: string) => string): never;
help(cb: (str: string) => string): never;

@@ -1499,0 +1519,0 @@ /**

@@ -1,25 +0,1 @@

const commander = require('commander');
exports = module.exports = {};
// Return a different global program than commander,
// and don't also return it as default export.
exports.program = new commander.Command();
/**
* Expose classes. The FooT versions are just types, so return Commander original implementations!
*/
exports.Argument = commander.Argument;
exports.Command = commander.Command;
exports.CommanderError = commander.CommanderError;
exports.Help = commander.Help;
exports.InvalidArgumentError = commander.InvalidArgumentError;
exports.InvalidOptionArgumentError = commander.InvalidArgumentError; // Deprecated
exports.Option = commander.Option;
exports.createCommand = (name) => new commander.Command(name);
exports.createOption = (flags, description) =>
new commander.Option(flags, description);
exports.createArgument = (name, description) =>
new commander.Argument(name, description);
export * from 'commander';
{
"name": "@commander-js/extra-typings",
"version": "14.0.0",
"version": "15.0.0",
"description": "Infer strong typings for commander options and action handlers",
"main": "index.js",
"main": "./index.js",
"scripts": {

@@ -15,3 +15,3 @@ "check": "npm run check:type && npm run check:lint && npm run check:format",

"prepublishOnly": "npm run --silent test",
"test": "tsd && jest"
"test": "tsd"
},

@@ -23,15 +23,12 @@ "repository": {

"files": [
"esm.mjs",
"esm.d.mts",
"index.js",
"index.d.ts"
],
"type": "commonjs",
"type": "module",
"exports": {
".": {
"require": "./index.js",
"import": "./esm.mjs"
"types": "./index.d.ts",
"default": "./index.js"
}
},
"types": "index.d.ts",
"tsd": {

@@ -48,19 +45,16 @@ "directory": "tests"

"peerDependencies": {
"commander": "~14.0.0"
"commander": "~15.0.0"
},
"devDependencies": {
"@jest/globals": "^29.3.1",
"@eslint/js": "^10.0.1",
"@types/node": "^22.10.1",
"commander": "~14.0.0",
"eslint": "^9.16.0",
"commander": "~15.0.0",
"eslint": "^10.0.2",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-jest": "^28.9.0",
"globals": "^15.0.0",
"jest": "^29.3.1",
"globals": "^17.0.0",
"prettier": "^3.2.5",
"ts-jest": "^29.0.5",
"tsd": "^0.31.2",
"typescript": "^5.3.3",
"tsd": "^0.33.0",
"typescript": "^6.0.2",
"typescript-eslint": "^8.11.0"
}
}

@@ -70,4 +70,3 @@ # extra-typings for commander

An alternative approach is to setup `@commander-js/extra-typings` as an ambient module and a development-only dependency. We only worked
this out recently so it isn't being promoted as the suggested method yet!
An alternative approach is to setup `@commander-js/extra-typings` as an ambient module and a development-only dependency.

@@ -91,1 +90,9 @@ Add a simple ambient module file to your project to use the enhanced typings instead of the default typings:

```
## Support
The 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.
Older major versions receive security updates for 12 months. For more see: [Release Policy](./docs/release-policy.md).
The main forum for free and community support is the project [Issues](https://github.com/commander-js/extra-typings/issues) on GitHub.
// Just reexport the types from cjs definition file.
export * from './index.js';
import extraTypingsCommander from './index.js';
// wrapper to provide named exports for ESM.
export const {
program,
createCommand,
createArgument,
createOption,
CommanderError,
InvalidArgumentError,
InvalidOptionArgumentError, // deprecated old name
Command,
Argument,
Option,
Help,
} = extraTypingsCommander;