Skip to content

Commit f306029

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

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;
@@ -192,7 +192,10 @@ export function createListenRouter(options: ListenRouterOptions): ListenRouter {
192192

193193
if (keepAliveMs > 0) {
194194
keepAliveTimer = setInterval(() => writeFrame(': keepalive\n\n'), keepAliveMs);
195-
// Do not hold the event loop open on idle subscriptions.
195+
// Do not hold the event loop open on idle subscriptions. Node's
196+
// setInterval returns a Timeout with .unref(); browsers/Workers
197+
// return a number — the cast is an environment shim, not a
198+
// workaround for SDK typing.
196199
(keepAliveTimer as { unref?: () => void }).unref?.();
197200
}
198201

@@ -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)