(Translated by https://www.hiragana.jp/)
`fn` type bound in `Server.register` might be slightly off · Issue #139 · elpheria/rpc-websockets · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn type bound in Server.register might be slightly off #139

Open
SamWilsn opened this issue Jun 21, 2023 · 2 comments
Open

fn type bound in Server.register might be slightly off #139

SamWilsn opened this issue Jun 21, 2023 · 2 comments

Comments

@SamWilsn
Copy link

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

register(name: string, fn: (params: IRPCMethodParams, socket_id: string) => void, ns = "/")

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:

response = await this.namespaces[ns].rpc_methods[message.method]
.fn(message.params, socket_id)

@mkozjak
Copy link
Member

mkozjak commented Jul 10, 2023

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

@SamWilsn
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants