microsoft / microsoft/TypeScript

Uncalled function checks don't work with negation

Open
#43,096 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.