Asked
Active
Viewed 154 times
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

עתודה אקדמאית
- 385
- 3
- 10
1 Answers
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
-
I think I know what's the problem. `WebSocket` in `ws` module is not an interface. It's the main class. Is there a way to do that now? – עתודה אקדמאית Sep 13 '20 at 22:28