You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
“This condition will always return true” is, in fact, false #61531
TS throws an error on line 12 which it shouldn't be throwing:
This condition will always return true since this 'Promise' is always defined.(2801)
input.tsx(12, 13): Did you forget to use 'await'?
🙂 Expected behavior
TS should not throw this error on line 12:
This condition will always return true since this 'Promise' is always defined.
It's making an opinion about a value at runtime that it doesn't have adequate context to adjudicate.
Additional information about the issue
That broader scope conditional on line 9 is narrowing the result type down from Promise<any> | null to Promise<any>, but then the check on line 12 is failing to account for the fact that result could get its value reassigned in virtue of the await on line 10. That await should cause the result type to expand back to the original Promise<any> | null, and make subsequent truthy checks allowable without type errors.
Ah, ok. Thanks, will close as duplicate. I saw that template but didn't initially think it fit. Reading it in full though I see what you're saying. Closing this as duplicate. Sorry for your time! Thanks.
Activity
MartinJohns commentedon Apr 4, 2025
Another duplicate of #9998. There's even a dedicated issue template for this: https://github.com/microsoft/TypeScript/blob/main/.github/ISSUE_TEMPLATE/types-not-correct-in-with-callback.md?plain=1
martynchamberlin commentedon Apr 4, 2025
Ah, ok. Thanks, will close as duplicate. I saw that template but didn't initially think it fit. Reading it in full though I see what you're saying. Closing this as duplicate. Sorry for your time! Thanks.