mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-09 06:58:02 -05:00
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]: f4d898ee96
Related: https://github.com/socketio/socket.io/issues/5202
This commit is contained in:
2
.github/workflows/build-examples.yml
vendored
2
.github/workflows/build-examples.yml
vendored
@@ -19,6 +19,8 @@ jobs:
|
||||
- custom-parsers
|
||||
- typescript-example/cjs
|
||||
- typescript-example/esm
|
||||
- typescript-client-example/cjs
|
||||
- typescript-client-example/esm
|
||||
- webpack-build
|
||||
- webpack-build-server
|
||||
- basic-crud-application/angular-client
|
||||
|
||||
30
examples/typescript-client-example/cjs/client.ts
Normal file
30
examples/typescript-client-example/cjs/client.ts
Normal file
@@ -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);
|
||||
17
examples/typescript-client-example/cjs/package.json
Normal file
17
examples/typescript-client-example/cjs/package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
9
examples/typescript-client-example/cjs/tsconfig.json
Normal file
9
examples/typescript-client-example/cjs/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "es2022",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
30
examples/typescript-client-example/esm/client.ts
Normal file
30
examples/typescript-client-example/esm/client.ts
Normal file
@@ -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);
|
||||
17
examples/typescript-client-example/esm/package.json
Normal file
17
examples/typescript-client-example/esm/package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
9
examples/typescript-client-example/esm/tsconfig.json
Normal file
9
examples/typescript-client-example/esm/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "es2022",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export class WS extends BaseWS {
|
||||
uri: string,
|
||||
protocols: string | string[] | undefined,
|
||||
opts: Record<string, any>,
|
||||
) {
|
||||
): any {
|
||||
if (this.socket?._cookieJar) {
|
||||
opts.headers = opts.headers || {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user