Skip to content

Commit f87dc5f

Browse files
refactor: use typescript strict setting
1 parent 511ac2f commit f87dc5f

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

lib/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { encode, decode } from "@msgpack/msgpack";
2-
import { Pool } from "pg";
2+
import { type Pool, type PoolClient, type Notification } from "pg";
33
import { ClusterAdapterWithHeartbeat, MessageType } from "socket.io-adapter";
44
import type {
55
ClusterAdapterOptions,
@@ -101,8 +101,8 @@ export function createAdapter(
101101

102102
const channelToAdapters = new Map<string, PostgresAdapter>();
103103
let isConnectionInProgress = false;
104-
let client: any;
105-
let cleanupTimer: NodeJS.Timer;
104+
let client: PoolClient | undefined;
105+
let cleanupTimer: NodeJS.Timeout;
106106

107107
const scheduleReconnection = () => {
108108
const reconnectionDelay = Math.floor(2000 * (0.5 + Math.random()));
@@ -120,11 +120,11 @@ export function createAdapter(
120120
await client.query(`LISTEN "${channel}"`);
121121
}
122122

123-
client.on("notification", async (msg: any) => {
123+
client.on("notification", async (msg: Notification) => {
124124
try {
125125
await channelToAdapters.get(msg.channel)?.onEvent(msg.payload);
126126
} catch (err) {
127-
errorHandler(err);
127+
errorHandler(err as Error);
128128
}
129129
});
130130

@@ -137,7 +137,7 @@ export function createAdapter(
137137
scheduleReconnection();
138138
});
139139
} catch (err) {
140-
errorHandler(err);
140+
errorHandler(err as Error);
141141
debug("error while initializing client, scheduling reconnection...");
142142
scheduleReconnection();
143143
}
@@ -150,7 +150,7 @@ export function createAdapter(
150150
`DELETE FROM ${tableName} WHERE created_at < now() - interval '${cleanupInterval} milliseconds'`
151151
);
152152
} catch (err) {
153-
errorHandler(err);
153+
errorHandler(err as Error);
154154
}
155155
scheduleCleanup();
156156
}, cleanupInterval);
@@ -182,7 +182,7 @@ export function createAdapter(
182182
if (client) {
183183
client.removeAllListeners("end");
184184
client.release();
185-
client = null;
185+
client = undefined;
186186
}
187187
if (cleanupTimer) {
188188
clearTimeout(cleanupTimer);
@@ -288,7 +288,7 @@ export class PostgresAdapter extends ClusterAdapterWithHeartbeat {
288288
payload,
289289
]);
290290
} catch (err) {
291-
this.errorHandler(err);
291+
this.errorHandler(err as Error);
292292
}
293293
}
294294

test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("@socket.io/postgres-adapter", () => {
1313
let servers: Server[],
1414
serverSockets: ServerSocket[],
1515
clientSockets: ClientSocket[],
16-
pool;
16+
pool: Pool;
1717

1818
beforeEach((done) => {
1919
servers = [];

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"allowJs": false,
55
"target": "es2017",
66
"module": "commonjs",
7-
"declaration": true
7+
"declaration": true,
8+
"strict": true
89
},
910
"include": [
1011
"./lib/**/*"

0 commit comments

Comments
 (0)