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

Coerce process.exitCode to number to match local usage #2209

Conversation

shadowspawn
Copy link
Collaborator

Pull Request

Problem

An update to @types/node showed up a subtle issue. process.exitCode allows a string representation of an integer. The Commander typings for the exit code are for a number, and the code assumes a number. So as well as the type not matching, there would actually be the wrong behaviour in the following line if the exitCode was "0"!

% npm run check:type:js

> commander@12.1.0 check:type:js
> tsc -p tsconfig.js.json

lib/command.js:2405:16 - error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
  Type 'string' is not assignable to type 'number'.

2405     this._exit(exitCode, 'commander.help', '(outputHelp)');
                    ~~~~~~~~


Found 1 error in lib/command.js:2405

Solution

Convert `process.exitCode to a number to keep things simple.

(So unlikely that this makes a difference to a real program that not including a changelog entry.)

@shadowspawn shadowspawn merged commit 19fa79f into tj:develop Jun 9, 2024
11 checks passed
@shadowspawn shadowspawn deleted the feature/stricter-types-with-process-exitcode branch June 9, 2024 10:02
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending release Merged into a branch for a future release, but not released yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants