Skip to content

Commit e1667d4

Browse files
committed
chore(bridge): clean up rpc peer typing
1 parent ab8bbb7 commit e1667d4

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

packages/bridge/src/rpc-peer.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import {
77
} from './protocol.js';
88
import type { RpcTransport } from './transport.js';
99

10-
type RpcMethod = (...args: any[]) => unknown;
10+
type RpcMethod = {
11+
bivarianceHack(...args: unknown[]): unknown;
12+
}['bivarianceHack'];
1113
type RpcMethods = Record<string, RpcMethod>;
1214

1315
type PendingInvocation = {
1416
args: unknown[];
1517
method: string;
1618
reject: (reason: unknown) => void;
17-
resolve: (value: any) => void;
19+
resolve: (value: unknown) => void;
1820
timeout: ReturnType<typeof setTimeout> | null;
1921
};
2022

2123
export type RpcPeer<
22-
Local extends RpcMethods,
2324
Remote extends RpcMethods,
2425
Event extends { type: string },
2526
> = {
@@ -53,7 +54,7 @@ export const createRpcPeer = <
5354
Event extends { type: string },
5455
>(
5556
options: CreateRpcPeerOptions<Local, Event>,
56-
): RpcPeer<Local, Remote, Event> => {
57+
): RpcPeer<Remote, Event> => {
5758
const pendingInvocations = new Map<number, PendingInvocation>();
5859
let nextMessageId = 1;
5960
let closedReason: Error | null = null;
@@ -100,7 +101,9 @@ export const createRpcPeer = <
100101
args,
101102
method: methodName,
102103
reject,
103-
resolve,
104+
resolve: (value) => {
105+
resolve(value as Awaited<ReturnType<Remote[typeof method]>>);
106+
},
104107
timeout: null,
105108
};
106109

@@ -132,7 +135,7 @@ export const createRpcPeer = <
132135

133136
reject(error);
134137
}
135-
}) as Promise<Awaited<ReturnType<Remote[typeof method]>>>;
138+
});
136139
},
137140
sendEvent: (event) => {
138141
if (closedReason) {

0 commit comments

Comments
 (0)