-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eio-client/types): remove ws type from .d.ts file
Before this change, the following error would be thrown when compiling with TypeScript: ``` node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:101 - error TS1340: Module 'ws' does not refer to a type, but is used as a type here. Did you mean 'typeof import('ws')'? 12 createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws"); ~~~~~~~~~~~~ ``` This behavior was introduced in [1], included in version `6.6.0`. The return type is forced as `any`, so that the `@types/ws` dependency is optional. [1]: f4d898e Related: #5202
- Loading branch information
1 parent
9b80ab4
commit 175a2c5
Showing
8 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { io, type Socket } from "socket.io-client"; | ||
|
||
interface ServerToClientEvents { | ||
hello: (val: string) => void; | ||
} | ||
|
||
interface ClientToServerEvents { | ||
ping: (cb: () => void) => void; | ||
} | ||
|
||
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io("ws://localhost:8080/"); | ||
|
||
socket.on("connect", () => { | ||
console.log(`connect ${socket.id}`); | ||
}); | ||
|
||
socket.on("hello", (val) => { | ||
console.log(`got ${val}`); | ||
}); | ||
|
||
socket.on("disconnect", () => { | ||
console.log(`disconnect`); | ||
}); | ||
|
||
setInterval(() => { | ||
const start = Date.now(); | ||
socket.emit("ping", () => { | ||
console.log(`pong (latency: ${Date.now() - start} ms)`); | ||
}); | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "typescript-client-example-cjs", | ||
"version": "0.0.1", | ||
"description": "An example with TypeScript", | ||
"type": "commonjs", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "ts-node client.ts" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"socket.io-client": "^4.8.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "es2022", | ||
"module": "nodenext", | ||
"moduleResolution": "nodenext", | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { io, type Socket } from "socket.io-client"; | ||
|
||
interface ServerToClientEvents { | ||
hello: (val: string) => void; | ||
} | ||
|
||
interface ClientToServerEvents { | ||
ping: (cb: () => void) => void; | ||
} | ||
|
||
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io("ws://localhost:8080/"); | ||
|
||
socket.on("connect", () => { | ||
console.log(`connect ${socket.id}`); | ||
}); | ||
|
||
socket.on("hello", (val) => { | ||
console.log(`got ${val}`); | ||
}); | ||
|
||
socket.on("disconnect", () => { | ||
console.log(`disconnect`); | ||
}); | ||
|
||
setInterval(() => { | ||
const start = Date.now(); | ||
socket.emit("ping", () => { | ||
console.log(`pong (latency: ${Date.now() - start} ms)`); | ||
}); | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "typescript-client-example-esm", | ||
"version": "0.0.1", | ||
"description": "An example with TypeScript", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "node --no-warnings=ExperimentalWarning --loader ts-node/esm client.ts" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"socket.io-client": "^4.8.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "es2022", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters