The following code is legal in TypeScript:
let asyncCondition = async(): Promise<boolean> => // .. calculate & return a boolean if(asyncCondition()){ // forgot to await. condition is always true // .. do stuff }
Since asyncCondition() returns a normal non-null Promise , the code in the if block will always be executed. This is JavaScript behavior, and it is clear that TypeScript is not complaining.
But in the above scenario, I had in mind:
let asyncCondition = async(): Promise<boolean> => // .. calculate & return a boolean if(await asyncCondition()){ // condition is asyncCondition() // .. do stuff }
Is there a way to let TypeScript print such errors for me?
typescript
Pinyin
source share