Reputation: 315
I'm trying to send messages in WebSocket with TypeScript. By staying this in my console, it works:
socket.on('displayHello', function(data) {
$.pnotify({
title: "Hello",
text: data.from + " te dis bonjour " + data.to,
type: "info"
});
});
I want to translate it into TypeScript :
public onMessage(): Observable<any> {
return new Observable(observer => {
this.socket.on('displayHello', (data) => {
observer.next(data);
});
});
}
I do not see how to do with the pnotify parameter because it is not recognized by TypeScript.
When I try this :
public onMessage(): Observable<any> {
return new Observable(observer => {
this.socket.on('displayHello', (data) => {
observer.next(data);
$.pnotify({
title: 'Hello',
text: data.from + ' te dis bonjour ' + data.to,
type: 'info'
});
});
});
}
I have this error :
TS2339:Property 'pnotify' does not exist on type '(search: string) => ElementFinder'
Upvotes: 0
Views: 108
Reputation: 2613
The problem you face could be solved by installing the type definition for pnotify
.
Depending if you're using npm or yarn you need to perform npm install --save-dev @types/jquery.pnotify
or yarn add --dev @types/jquery.pnotify
.
Also make sure that you're using a recent version of TypeScript that does automatically locate type definitions within the @types/
-Folder
Upvotes: 1