-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Suggestion
π Search Terms
This condition will always return true since this 'Promise<string | undefined>' is always defined.(2801) Did you forget to use 'await'?
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
When checking the inverted truthyness if something returned from an async
function without calling await
, it should warn you you forgot await
. This works without inverting.
π Motivating Example
async function foo(): Promise<string | undefined> {
return
}
const value = foo()
if (!value) { // <-- fails silently
// ...
}
const awaitedValue = await foo()
if (awaitedValue) { // <-- Emits ts2801
// ...
}
π» Use Cases
In my use, I had a function that returned a User | undefined
and I was doing something if there wasn't a user returned. Later, I made the function async and forgot to update this since it was failing silently.
DetachHead, stickyfingies, h-joo and tjenkinson
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript