Having trouble with setting up web sockets. The code I have below is not compiling in TypeScript:
let observer = {
error: null,
complete: null,
next: (data: Object) => {
console.log('Message sent to websocket: ', data);
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
}
};
return new AnonymousSubject<MessageEvent>(observer, observable);
The red underlined observer
variable shows this message:
Argument of type '{ error: null; complete: null; next: (data: Object) => void; }' is not assignable to parameter of type 'Observer<MessageEvent<any>>'.
Types of property 'error' are incompatible.
Type 'null' is not assignable to type '(err: any) => void'.ts(2345)
Any suggestions on how to fix the compilation issue?