Having trouble with a messaging app, specifically an error related to TS.
The syntax checker in the Editor is flagging this issue: Type 'Observable<{}>' is not compatible with type 'Observable'. Type '{}' cannot be assigned to type 'MessageThread[]'. Property 'includes' is missing in type '{}'.
The CODE
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import * as io from 'socket.io-client';
import { MessageThread } from './message-thread.model';
@Injectable()
export class MessageThreadService {
private getMessageThreadsUrl = 'api/message-thread/get';
private postMessageThreadsUrl = 'api/message-thread/post';
constructor(private http: Http) { }
private socket;
private url = window.location.origin;
/*
* Get MessageThreads from server
*/
getMessageThreads(): Observable<MessageThread[]> {
const observable = new Observable(observer => {
console.log('Socket:', this.url);
this.socket = io(this.url);
this.socket.on('refreshMessageThreads', (data) => {
observer.next(data);
});
return () => {
this.socket.disconnect();
};
});
return observable;
}
...
An error is being thrown by the angular transpiler:
ERROR in src/app/components/messages/message-thread.service.ts(35,3): error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable'. Type '{}' is not assignable to type 'MessageThread[]'. Property 'includes' is missing in type '{}'.
This is how the Message Thread Model is structured:
export class MessageThread {
constructor(
public messageThread: string
) { }
}
Any help would be greatly appreciated.