-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Stricter handling of promises/async functions #55791
Comments
|
You should continue to use |
Hm, there appears to be more interest from the team than I suspected, however see discussion starting here, this is apparently a bigger can of worms than it looks at first: #13376 (comment) Also: #13376 (comment) |
With the new daemon mode, the type-aware ESLint rule is a good move at minimum, but I agree that thereβs a serious need here. Itβs not in the usual correctness bucket, but in practice dangling promises are one of the major contributors to memory leaks, especially in cases where you expect a short-lived request on a server and "close" it by whatever means, but the promise is still dangling. (Ask me how I know, he says, shuddering to remember the first 4 months of the year.) |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh can you clarify which issue(s) this is a duplicate of? |
π Search Terms
"promise", "dangling promise", "async", "floating promise"
β Viability Checklist
β Suggestion
I think it would be valuable for TypeScript to have an option enabling stricter checks on async functions and promises. Things like:
Array.forEach()
:1) is currently handled by https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-floating-promises.md.
2) isn't handled by any common tooling that I'm aware of.
Promises and async/await are common patterns used in JavaScript, and there are a whole class of possible bugs that could be eliminated from stricter TypeScript checking. Some of these are currently handled by third-party linters like ESLint, but misuse of promises are so common, and so likely to be bugs, that I think they deserve to be brought into TypeScript as compile errors. Another benefit is that it prevents users from having to run 2 different tools, each constructing their own ASTs, to get compile-time safety.
To avoid breaking existing TypeScript code, we could gate this change behind a flag for users to decide when/if to opt in.
π Motivating Example
Stricter handling of promises to avoid writing bugs in async code.
Note these kind of checks exist in other statically typed languages and type checkers, such as:
π» Use Cases
The text was updated successfully, but these errors were encountered: