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

Add feature to indicate when calling an async method that has await key omitted #57359

Closed
4 of 6 tasks
velara3 opened this issue Feb 9, 2024 · 5 comments
Closed
4 of 6 tasks
Labels
Duplicate An existing issue was already created

Comments

@velara3
Copy link

velara3 commented Feb 9, 2024

🔍 Search Terms

await async promise

✅ Viability Checklist

⭐ Suggestion

In a typescript project, after creating an async method the next step would be to use it. Adding an warning if await is not used is helpful for debugging.

But async methods have different behavior if you use the await keyword before hand.

Calling this function:

async doSomething() {
    // make an async call or action usually
     return await fetch(url)
}

// this first call results are different than the second call results
var aPromise = doSomething();
var aResponseObject = await doSomething();

// this first call is different than second 
var aPromise = doSomething();
console.log("This line is called immediately even though doSomething is not finished it's task")
var aResponseObject = await doSomething();
console.log("This line is not called until after doSomething has a result from the server") 

In the first call the program flow continues to the next line.
In the second call the program execution flow pauses.

Both cases are valid but having a warning (not an error) for the cases when the awaitkeyword is missing would be very desirable.

I don't know how many times my code has behaved unexpectedly and the unexpected behavior is due to a missing await keyword for an async function. Having a simple indication in typescript gives me an notice that maybe I need to add an await.

📃 Motivating Example

"A new feature in Typescript will alert you when your code omits the await keyword when calling async methods, saving developers hours of time for hard to track bugs!"

💻 Use Cases

  1. What do you want to use this for?
  • for assistance during development
  1. What shortcomings exist with current approaches?
    if you don't use await on an async method there's no indication that the call is no longer waiting or pausing the execution flow. there's no way to tell when debugging if the function is inside of an async program execution

  2. What workarounds are you using in the meantime?
    pulling out my hair saves money on haircuts

@velara3 velara3 changed the title Add option to indicate when calling an async method that has await key omitted Add feature to indicate when calling an async method that has await key omitted Feb 9, 2024
@MartinJohns
Copy link
Contributor

but having a warning (not an error)

TypeScript does not have the concept of warnings. There are only errors.

@RyanCavanaugh
Copy link
Member

Duplicate #13376

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 9, 2024
@fatcerberus
Copy link

"A new feature in Typescript will alert you when your code omits the await keyword when calling async methods, saving developers hours of time for hard to track bugs!"

That's not a motivating example... motivational, yes, but not a motivating example.

pulling out my hair saves money on haircuts

Significantly more painful, though.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@velara3
Copy link
Author

velara3 commented Feb 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants