Repository navigation
Uncalled Function Checks don't check negative condition #34815
Description
Activity
- addedAwaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
on Oct 30, 2019 brandon-leapyear commented
on Feb 17, 2021 More actions✨ This is an old work account. Please reference Brandon Chinn (@brandonchinn178) for all future communication ✨
Very much agree with this. In our code, we just got bit by
if (!nock.isActive) { nock.activate() }
In general, I would usually not intentionally want
!foo, and if I did want to do something like that, I would dofoo === undefined. Even more generally, I would personally disallow coercion from function to boolean completely. Forcing devs to writefoo === undefinedwould make it clear what their intention is, and would force the dev to typefooasFunction | undefined, if that's truly what they want.This bit me last week in one of the codebases I maintain. I also see that it's bitten a number of others:
There's relevant info in:- Uncalled function checks don't work with negation #43096, which is a duplicate issue
- TS: no longer seeing an error when not calling function in check vscode#91144
- One attempted fix at Uncalled function checks don't work with negation #43097, which was almost accepted.
Daniel Rosenwasser (@DanielRosenwasser), would the TS team accept a contribution for this? I've optimistically opened a PR at #57114
RyanCavanaugh commented
on Jan 23, 2024 MemberMore actionsThere are many, many false positives turned up in that PR. Unless these were ~all good finds, I think this is appropriately left still in "awaiting more feedback" state
The tool for finding false positives is super neat. It makes sense to me to not merge this -- I followed ~20 links and I think this was the only legitimate bug I found (it should have an await). The rest were all just undefined checks on things that the typings say should always be defined.
I'm happy to close out that PR (or have you close it). Whatever works for you.
Expected: Error on
!foothat the condition is always true becausefoois defined.Actual: No error.
Also, any work on this should include the following test: