rpc-websockets icon indicating copy to clipboard operation
rpc-websockets copied to clipboard

`fn` type bound in `Server.register` might be slightly off

Open SamWilsn opened this issue 2 years ago • 2 comments

The type bound for fn in register has a void return type:

https://github.com/elpheria/rpc-websockets/blob/46b0190bc0ecdce4236b7ccbe93b5e687a5aaf09/src/lib/server.ts#L147

I'm rather new to TypeScript, but I would suggest a return type of unknown | Promise<unknown> to hint that the function is await'd later on:

https://github.com/elpheria/rpc-websockets/blob/46b0190bc0ecdce4236b7ccbe93b5e687a5aaf09/src/lib/server.ts#L697-L698

SamWilsn avatar Jun 21 '23 20:06 SamWilsn

Hi, @SamWilsn, are there any issues you came across in production that's touching on this code?

mkozjak avatar Jul 10 '23 13:07 mkozjak

are there any issues you came across in production that's touching on this code?

Here's an example:

https://github.com/wallet-test-framework/glue-ws/blob/0322225d8979f2d3995efb1d703d98c6f672f75d/src/index.ts#L68-L70

I have to disable the @typescript-eslint/no-misused-promises lint because the function doesn't declare that it may return a Promise.

SamWilsn avatar Jul 10 '23 18:07 SamWilsn