commander.js icon indicating copy to clipboard operation
commander.js copied to clipboard

Missing `this` type for `action`

Open matthyk opened this issue 2 years ago • 5 comments

https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/command.js#L511-L527 The passed action function fn receives the current command as this context in line 523. However, this context is missing in the current typings. https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/typings/index.d.ts#L525

Happy to provide a PR for this!

matthyk avatar Feb 05 '24 15:02 matthyk

I had seen this recommended in the Effective TypeScript book, but not acted on it as I was not familiar with the pattern (Item 49: Provide a Type for this in Callbacks).

shadowspawn avatar Feb 05 '24 21:02 shadowspawn

We have more advanced typings and try out some typing improvements in: https://github.com/commander-js/extra-typings

If you open a PR there, we can make it available there first before bringing it back to Commander.

shadowspawn avatar Feb 05 '24 22:02 shadowspawn

Done with https://github.com/commander-js/extra-typings/pull/59 🎉

matthyk avatar Feb 06 '24 08:02 matthyk

The change has been out for a couple of months in https://github.com/commander-js/extra-typings without causing reported issues.

Would you still like to make a PR here @matthyk ?

shadowspawn avatar May 19 '24 00:05 shadowspawn

Absolutely!

matthyk avatar May 19 '24 13:05 matthyk