eduardogbg eduardogbg - 1 year ago 140
Node.js Question

How can I extend Node's stream

I'm trying to create a method for Readable Stream, but after trying just a little bit, I ran out of ideas to how.

import * as stream from 'stream'
//yields Property 'asdasas' does not exists on type 'Readable'
//yields asdas does not exists on type 'typeof Readable'

Can someone give me a solution and explain why the errors happened? Thanks

Answer Source

I managed to extend them. The behaviour wasn't as unusual as I thought (I still would appreciate an explanation on the difference of "type 'Readable'" and "type 'typeof Readable'". The code:

import * as stream from 'stream'

class mod_Readable extends stream.Readable {
    pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T {
        return super.pipe(destination, options)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download