uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.76k stars 563 forks source link

Server get/post/...etc handlers cannot be async and return promise according to current TS typings #889

Closed JerryCauser closed 1 year ago

JerryCauser commented 1 year ago

Right now if I try to use async function as any kind of handlers (get/post/etc...) typescript will alarming me about non-correct type of handler function. It accepts only plain void function.

JerryZhongJ commented 11 months ago

Right now if I try to use async function as any kind of handlers (get/post/etc...) typescript will alarming me about non-correct type of handler function. It accepts only plain void function.

I am doing a research about bugs in TypeScript, and I am trying to reproduce this bug. But I succeed to assign an async function to a property typed as returning void, just like WebSocketBehavior.message, without any alarms. It turns out that a function returning Promise can be assigned to that returning void, according to this stackoverflow

May I ask what your case was and how the alarm showed?

JerryCauser commented 11 months ago

@JerryZhongJ I'm using ts-standard and it was pushing some error. I don't remember which one. You can try to reimplement it by yourself by installing ts-standard and desired version of uWS.js.

JerryCauser commented 10 months ago

@JerryZhongJ @typescript-eslint/no-misused-promises

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-misused-promises.md#checksvoidreturn