-
Notifications
You must be signed in to change notification settings - Fork 12.8k
False positive from TS2801 (Promise<...> appears to always be defined) #43565
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
Comments
I just saw @andrewbranch's comment on #43514
That's what I've done here but there is still an error, in spite of explicitly adding |
But TypeScript is right. The value |
It's not. You clearly assign a non-falsy value to your variable, so the variable is narrowed. This is the intentional behavior.
is essentially the sama as
And you wouldn't expect an error to call a function on your number right away, would you?
This is the same issue and absolutely intentional. |
You can get the behavior you want by using a type assertion:
Now TypeScript won't narrow |
@MartinJohns thanks for the detailed explanation, I deleted my comment, none of it made sense... I guess this is a duplicate of #43514 then since the only real example arises when you access |
At least the examples given here so far are not related to #43514.
|
Yeah, this whole issue is my bad. I totally misspoke when I wrote this, and had intended to use |
Bug Report
See code snippet below, if a type is a union with undefined it shouldn't throw the TS2801 error "This condition will always return true since this 'Promise' appears to always be defined."
Especially not when
strictNullChecks: true
🔎 Search Terms
🕗 Version & Regression Information
v4.3.0-beta
⏯ Playground Link
Playground link,
strictNullChecks
is on💻 Code
🙁 Actual behaviour
"This condition will always return true since this 'Promise' appears to always be defined."
🙂 Expected behaviour
no error
The text was updated successfully, but these errors were encountered: