Skip to content

Commit 9b1af95

Browse files
refactor: improve types (2)
1 parent e5d912d commit 9b1af95

File tree

5 files changed

+15
-28
lines changed

5 files changed

+15
-28
lines changed

lib/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ export class Server extends BaseServer {
753753

754754
if (req._query.sid) {
755755
debug("setting new request for existing client");
756-
// @ts-ignore
757756
this.clients[req._query.sid].transport.onRequest(req);
758757
} else {
759758
const closeConnection = (errorCode, errorContext) =>

lib/transport.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export abstract class Transport extends EventEmitter {
8080
*
8181
* @param {EngineRequest} req
8282
*/
83-
constructor(req: EngineRequest) {
83+
constructor(req: { _query: Record<string, string> }) {
8484
super();
8585
this.protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
8686
this.parser = this.protocol === 4 ? parser_v4 : parser_v3;
@@ -99,10 +99,10 @@ export abstract class Transport extends EventEmitter {
9999
/**
100100
* Called with an incoming HTTP request.
101101
*
102-
* @param {EngineRequest} req
103-
* @protected
102+
* @param {http.IncomingMessage} req
103+
* @package
104104
*/
105-
protected onRequest(req: EngineRequest) {
105+
onRequest(req) {
106106
debug("setting request");
107107
this.req = req;
108108
}
@@ -172,18 +172,18 @@ export abstract class Transport extends EventEmitter {
172172
/**
173173
* The name of the transport.
174174
*/
175-
abstract get name();
175+
abstract get name(): string;
176176

177177
/**
178178
* Sends an array of packets.
179179
*
180180
* @param {Array} packets
181181
* @package
182182
*/
183-
abstract send(packets);
183+
abstract send(packets): void;
184184

185185
/**
186186
* Closes the transport.
187187
*/
188-
abstract doClose(fn?: () => void);
188+
abstract doClose(fn?: () => void): void;
189189
}

lib/transports/polling-jsonp.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ export class JSONP extends Polling {
1919
this.foot = ");";
2020
}
2121

22-
/**
23-
* Handles incoming data.
24-
* Due to a bug in \n handling by browsers, we expect a escaped string.
25-
*
26-
* @protected
27-
*/
28-
protected onData(data: RawData) {
22+
override onData(data: RawData) {
2923
// we leverage the qs module so that we get built-in DoS protection
3024
// and the fast alternative to decodeURIComponent
3125
data = qs.parse(data).d as string;
@@ -39,12 +33,7 @@ export class JSONP extends Polling {
3933
}
4034
}
4135

42-
/**
43-
* Performs the write.
44-
*
45-
* @protected
46-
*/
47-
protected doWrite(data, options, callback) {
36+
override doWrite(data, options, callback) {
4837
// we must output valid javascript, not valid json
4938
// see: http://timelessrepo.com/json-isnt-a-javascript-subset
5039
const js = JSON.stringify(data)

lib/transports/polling.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Polling extends Transport {
4343
* Overrides onRequest.
4444
*
4545
* @param {EngineRequest} req
46-
* @private
46+
* @package
4747
*/
4848
onRequest(req: EngineRequest) {
4949
const res = req.res;
@@ -65,7 +65,7 @@ export class Polling extends Transport {
6565
*
6666
* @private
6767
*/
68-
onPollRequest(req, res) {
68+
private onPollRequest(req: EngineRequest, res: ServerResponse) {
6969
if (this.req) {
7070
debug("request overlap");
7171
// assert: this.res, '.req and .res should be (un)set together'
@@ -107,7 +107,7 @@ export class Polling extends Transport {
107107
*
108108
* @private
109109
*/
110-
onDataRequest(req: IncomingMessage, res: ServerResponse) {
110+
private onDataRequest(req: IncomingMessage, res: ServerResponse) {
111111
if (this.dataReq) {
112112
// assert: this.dataRes, '.dataReq and .dataRes should be (un)set together'
113113
this.onError("data request overlap from client");
@@ -182,7 +182,7 @@ export class Polling extends Transport {
182182
* @param data - encoded payload
183183
* @protected
184184
*/
185-
protected onData(data: RawData) {
185+
override onData(data: RawData) {
186186
debug('received "%s"', data);
187187
const callback = (packet) => {
188188
if ("close" === packet.type) {
@@ -312,7 +312,7 @@ export class Polling extends Transport {
312312
*
313313
* @private
314314
*/
315-
compress(data, encoding, callback) {
315+
private compress(data, encoding, callback) {
316316
debug("compressing");
317317

318318
const buffers = [];
@@ -335,7 +335,7 @@ export class Polling extends Transport {
335335
*
336336
* @private
337337
*/
338-
doClose(fn: () => void) {
338+
override doClose(fn: () => void) {
339339
debug("closing");
340340

341341
let closeTimeoutTimer;

lib/transports/webtransport.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export class WebTransport extends Transport {
1111
private readonly writer;
1212

1313
constructor(private readonly session, stream, reader) {
14-
// @ts-expect-error
1514
super({ _query: { EIO: "4" } });
1615

1716
const transformStream = createPacketEncoderStream();

0 commit comments

Comments
 (0)