Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript and Socket.io

I would like to use socket.io in my Typescript project, but I've only found .d.ts files for server-side typescript.

This is a nice example: https://github.com/soywiz/typescript-node-definitions/blob/master/socket.io.d.ts

It shows how to use TypeScript in combination with Socket.io. However on the client side it uses JavaScript.

What I need is a .d.ts file for client-side TypeScript, that resolves the error message from this line:

var socket=io.connect("localhost");

The name "io" does not exist in the current scope

Where can I find the appropriate definition file?

like image 759
lhk Avatar asked Dec 29 '12 17:12

lhk


People also ask

What is difference between Socket and IO?

Key Differences between WebSocket and socket.ioIt provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback. WebSocket is the technology, while Socket.io is a library for WebSockets.

Which is better Socket.IO or WebSockets?

Socket.IO is way more than just a layer above WebSockets, it has different semantics (marks messages with name), and does failovers to different protocols, as well has heartbeating mechanism. More to that attaches ID's to clients on server side, and more. So it is not just a wrapper, it is full-featured library.

Is WebSocket and Socket.IO same?

Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server. It is built on top of the WebSocket protocol and provides additional guarantees like fallback to HTTP long-polling or automatic reconnection.


1 Answers

There is @types/socket.io now, just install it by running:

npm i --save @types/socket.io

like image 163
Nick D Avatar answered Oct 20 '22 04:10

Nick D