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

fix: update types for defaultValue #2237

Closed
wants to merge 1 commit into from

Conversation

Sadzurami
Copy link

@Sadzurami Sadzurami commented Aug 21, 2024

Problem

Wrong typings for defaultValue
ref: #2236

Solution

Force defaultValue to any type.
Commander actually don't check types at code (except undefined) when use value.

We see that the tests pass successfully with types other then defined now.

test('when default value is defined (without custom processing) and argument not specified with action handler then action argument is default value', () => {
const defaultValue = 1;
let actionValue;
const program = new commander.Command();
program.argument('[n]', 'number', defaultValue).action((arg) => {
actionValue = arg;
});
program.parse([], { from: 'user' });
expect(actionValue).toEqual(defaultValue);
expect(program.processedArgs).toEqual([defaultValue]);
});

@shadowspawn
Copy link
Collaborator

I am aware that the JavaScript allows any type, but we are stricter in the TypeScript.

See similar closed PR #1792

And the Pull Request that removed multiple uses of any including for the .option() default value: #1119

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

Successfully merging this pull request may close these issues.

2 participants