Skip to content

Commit e324db7

Browse files
refactor(server): drop type assertions in listenRouter via narrowed locals
1 parent 02e5d3b commit e324db7

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/server/src/server/listenRouter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function stampSubscriptionId(
8585
* marks `notifications` REQUIRED on the listen request).
8686
*/
8787
export function parseListenFilter(message: JSONRPCRequest): SubscriptionFilter | undefined {
88-
const raw = (message.params as { notifications?: unknown } | undefined)?.notifications;
88+
const raw: unknown = message.params?.['notifications'];
8989
if (raw === undefined) return undefined;
9090
const parsed = SubscriptionFilterSchema.safeParse(raw);
9191
return parsed.success ? parsed.data : undefined;
@@ -193,7 +193,10 @@ export function createListenRouter(options: ListenRouterOptions): ListenRouter {
193193
if (keepAliveMs > 0) {
194194
keepAliveTimer = setInterval(() => writeFrame(': keepalive\n\n'), keepAliveMs);
195195
// Do not hold the event loop open on idle subscriptions.
196-
(keepAliveTimer as { unref?: () => void }).unref?.();
196+
// Node's setInterval returns a Timeout with .unref(); browsers return a number.
197+
if (typeof keepAliveTimer === 'object' && 'unref' in keepAliveTimer && typeof keepAliveTimer.unref === 'function') {
198+
keepAliveTimer.unref();
199+
}
197200
}
198201

199202
open.add(teardown);
@@ -331,7 +334,8 @@ export class StdioListenRouter {
331334
if (!CHANGE_NOTIFICATION_METHODS.has(message.method)) {
332335
return 'passthrough';
333336
}
334-
const uri = typeof message.params?.['uri'] === 'string' ? (message.params['uri'] as string) : undefined;
337+
const uriParam: unknown = message.params?.['uri'];
338+
const uri = typeof uriParam === 'string' ? uriParam : undefined;
335339
const event = notificationToServerEvent(message.method, uri);
336340
const out: NotificationBody[] = [];
337341
for (const [subscriptionId, filter] of this._subs) {

0 commit comments

Comments
 (0)