0

I'm using `express-ws` for WebSockets.
I want to extend the `WebSocket` class in the `ws` module that `express-ws` import and add it a string as prototype. (`WebSocket.prototype.str: string = ""`).
i should mention that I'm using typescript.
Who can I do it? Thanks

1 Answers1

0

This may work. Just makesure that WebSocket is an interface

import {WebSockets} from './express-ws';

interface WebSocket {
    str:string;
}


// Type definition for the spy function 
declare module './express-ws' {
    namespace WebSockets {
        export interface WebSocket {
            str: string;
        }
    }
}
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72