Brettetete Brettetete - 1 year ago 1018
TypeScript Question

NodeJS EventEmitter with TypeScript class

Is it possible to use NodeJS'

with a TypeScript class? If yes, how?

I've tried countless variations in the last hours to get this working, so I won't list any of them.

What I basically want to do:

export class Database{
constructor(cfg:IDatabaseConfiguration) {
mongoose.connect(cfg.getConnectionString(), cfg.getCredentials(), function (err:any) {
if (err)
this.emit('error', err);

Answer Source

You should download node typings:

$ tsd install node --save

and then just use the following code:

///<reference path="./typings/node/node.d.ts" />
import events = require('events');

class Database{
    constructor() {;

I simplified it to test your main problem.

Edit: Modified based on your comment:

///<reference path="./typings/node/node.d.ts" />
import events = require('events');

class Database extends events.EventEmitter {
    constructor() {

new Database();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download