Commander.js: Typescript type definitions incorrect for Command class

Created on 9 Apr 2018  路  8Comments  路  Source: tj/commander.js

When compiling a typescript project the following error is produced

node_modules/commander/typings/index.d.ts(26,25): error TS2689: Cannot extend an interface 'NodeJS.EventEmitter'. Did you mean 'implements'?
docs

Most helpful comment

Adding @types/node to devDependencies has fixed the issue for us.

All 8 comments

Same issue for me - commander - 2.15.1, typescript 2.8.1.
Workaround is to remove the extends statement
before:
class Command extends NodeJS.EventEmitter {
after:
class Command {
Command does not implement any of the EventEmmiter's functions.

Adding @types/node to devDependencies has fixed the issue for us.

I also get an error TypeError: cmd.command is not a function
using with TypeScript 2.9.1

@types/node should be added as a dependency in commender.js. As a temporary solution, I add it to my own package before this done.

We should document that intend end-user to install @types/node.

Added TypeScript tips in README. Hopefully that helps.
https://github.com/tj/commander.js#typescript

Same issue for me - commander - 2.15.1, typescript 2.8.1.
Workaround is to remove the extends statement
before:
class Command extends NodeJS.EventEmitter {
after:
class Command {
Command does not implement any of the EventEmmiter's functions.

Thank you! This solution works for Electron 9 and Node 12.

For future readers still using older versions of Commander, I'll add a link to the older README instructions:
https://github.com/tj/commander.js/tree/v4.1.1#typescript

The TypeScript dependency on NodeJS.EventEmitter was removed in #1146 which shipped in Commander v5.0.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RoXioTD picture RoXioTD  路  4Comments

hossamelmansy picture hossamelmansy  路  4Comments

shadowspawn picture shadowspawn  路  3Comments

mtrabelsi picture mtrabelsi  路  3Comments

jaredpetersen picture jaredpetersen  路  3Comments