Like the title states, I would like to rewrite the statement below in TypeScript
EventEmitter = require('events').EventEmitter
to ES6 style
import {EventEmitter} from "events"
I'm not sure whether these two are equivalent, in fact I think they aren't because when I'm trying to use RxJS with the second statement above it doesn't compile the example below whereas it does with the first one.
I'm getting the following error when I'm using the second statement above.
.build/lib/process.ts(12,3): error TS2345: Argument of type 'EventEmitter' is not assignable to parameter of type '{ on: (name: string, cb: (e: any) => any) => void; off: (name: string, cb: (e: any) => any) => vo...'.
Property 'off' is missing in type 'EventEmitter'.
Example:
var EventEmitter = require('events').EventEmitter,
Rx = require('rx');
var eventEmitter = new EventEmitter();
var source = Rx.Observable.fromEvent(
eventEmitter,
'data',
function (foo, bar) { return { foo: bar, bar: bar }; });
var subscription = source.subscribe(
function (x) {
console.log('Next: foo -' + x.foo + ', bar -' + x.bar);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
eventEmitter.emit('data', 'baz', 'quux');
// => Next: foo - baz, bar - quux