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
Uncalled function checks don't work when the variable is referenced in the block #43211
// @strictNullChecks: truedeclarefunctionisFoo(): boolean;declarefunctionisBar(): boolean;if(isFoo){// uncalled function checks already work well here}if(isFoo&&isBar()){// uncalled function checks already work well here}if(isFoo&&isFoo()){// uncalled function checks should cover this case too}if(isFoo&&isBar()){isFoo;// uncalled function checks should cover this case too}
🙁 Actual behavior
In the last two cases we didn't detect that the first occurrence of isFoo in the condition is uncalled.
🙂 Expected behavior
When isFoo cannot possibly be a falsy value (i.e. undefined) we should highlight this as an error even if isFoo occurs again later on. This is a follow-up to a conversation in #42835 (comment).
I would be happy to enable this check, then we could run this against some user tests and decide whether there are too many false positives 🙂
Ryan Cavanaugh (@RyanCavanaugh) I'm probably misunderstanding your example, but if isFoo cannot possible be undefined, isn't the condition in the example you gave above redundant?
It's intentional that the rule is not ironclad. This is because there are some places in the language where TS thinks something is always not-undefined, but it's not necessarily the case.
Activity
RyanCavanaugh commentedon Mar 12, 2021
A reference should be sufficient here to not complain, since you might write something like
jonhue commentedon Mar 12, 2021
Ryan Cavanaugh (@RyanCavanaugh) I'm probably misunderstanding your example, but if
isFoocannot possible beundefined, isn't the condition in the example you gave above redundant?RyanCavanaugh commentedon Mar 12, 2021
It's intentional that the rule is not ironclad. This is because there are some places in the language where TS thinks something is always not-
undefined, but it's not necessarily the case.