fardjad / node-interactive-commander

Commander.js with integrated interactive prompts
https://www.npmjs.com/package/interactive-commander
MIT License
6 stars 1 forks source link

Inherit `Command` and `Option` from `@commander-js/extra-typings` for better type hint? #251

Open BrandenXia opened 3 months ago

BrandenXia commented 3 months ago

@commander-js/extra-typings provide a better support for typescript and works exactly same as the Command and Option in commander.js. The only required change is to add @commander-js/extra-typings as dependency and inherit Command and Option from @commander-js/extra-typings instead of commander

BrandenXia commented 3 months ago

Just opened a pull request 😄

fardjad commented 3 months ago

Hi @BrandenXia

Thanks for contributing to the repository.

The test workflows fail because the package-lock.json file is out of sync with package.json. I tried fixing that locally, but then I got some type errors:

Found 20 errors in 7 files.

Errors  Files
     3  examples/dependent-prompts.ts:45
     3  examples/npm-init.ts:120
     1  examples/order-pizza.ts:68
     4  src/interactive-command.test.ts:91
     4  src/interactive-command.ts:115
     4  src/interactive-option.test.ts:76
     1  src/interactive-option.ts:51

Would you mind fixing these?

Please let me know once the tests run successfully (npm test) and we'll take another look at your PR ✌🏼

BrandenXia commented 3 months ago

I just realized that since the signature of chained function in Command class return Command instead of InteractiveCommand, it cannot be typed correctly. A possible solution might be overriding signature of all the chained function (which doesn't work so well). A better solution is to use this instead of Command in the function signature in parent class, I might need to make a pull request to @commander-js/extra-typings too. 😂

Edit: According to the readme, using this will break the type inference. I might need to think of another solution.