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

Update index.d.ts #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

juliusmarminge
Copy link

@juliusmarminge juliusmarminge commented Jun 14, 2024

excuse me if this is invalid but from reading the examples it seems like async functions are allowed, so the return type should accept a promise?

i've been thrown off from all the synchronous types in Fastify the last couple of days, so perhaps this should be looked over in other parts of the ecosystem too

Signed-off-by: Julius Marminge <julius0216@outlook.com>
@mcollina
Copy link
Member

What examples? Are those on our website?

You really should not use async here, nor in most other middleware, because there is no real error handling for rejecting promises. Nor there is in express or connect etc.

In essence, the types are telling you that what you are doing is essentially unsafe, because it is.

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 11, 2024

In express v4 I needed to use this one "hack" where you could have async handlers. I think express v5 has native async handler support.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we do not handle promises here. A rejection in one of those promise would lead to a unhandledRejection, therefore making it problematic. We could support this, but work to add it should be done to library, not just the types.

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

Successfully merging this pull request may close these issues.

4 participants