microsoft / microsoft/TypeScript
Uncalled function checks don't work with negation
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
uncalled function checks, negation
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
declare function isFoo(): boolean;
declare const isUndefinedFoo: (() => boolean) | undefined;
if (isFoo) {
// uncalled function checks already work well here
}
if (!isFoo) {
// uncalled function checks should cover this case too
}
if (!isUndefinedFoo) {
// this case should not be covered
}
🙁 Actual behavior
Uncalled function checks do not work with the ! operator.
🙂 Expected behavior
Unless a function may be undefined it would be very helpful to check whether it is called when it is used with the ! operator.
I created this issue to separate a part of the implementation of #42835 resulting from issue #35584. This specific issue was inspired by https://github.com/microsoft/TypeScript/issues/35584#issuecomment-769401594.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior in the linked TypeScript Playground, comparing the positive and negated checks for isFoo and isUndefinedFoo. Read the uncalled-function-check implementation associated with #42835 and the discussion in #35584; done means negation reports definitely-defined uncalled functions without incorrectly reporting possibly undefined functions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100