I am currently working on implementing SignalR into my Angular 5 application.
To do this, I added the following TypeScript type definitions from DefinitelyTyped:
npm install --save @types/jquery
npm install --save @types/signalr
The version of Typescript in my packages.json
is 2.5.3.
Here is how I'm attempting to use SignalR:
import { Injectable } from '@angular/core';
@Injectable()
export class SignalRService {
constructor() {}
public ConnectTo(url: string): void {
var hubConnection = $.hubConnection();
var hubProxy = hubConnection.createHubProxy('DashboardHub');
hubProxy.on('Example', (e: any) => {
console.log('worked');
});
hubConnection.start();
}
}
However, the compiler is showing the following error:
error TS2304: Cannot find name '$'.
Interestingly, intellisense can recognize $.hub
:
https://i.sstatic.net/X1kgP.png
I tried adding declare var $ :any;
to my file which resolved the compile error, but resulted in another error in the browser's console:
$.hubConnection is not a function
.
Am I overlooking something crucial?