Skip to content
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

Uncalled function checks don't work with negation #43096

Open
jonhue opened this issue Mar 5, 2021 · 1 comment
Open

Uncalled function checks don't work with negation #43096

jonhue opened this issue Mar 5, 2021 · 1 comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@jonhue
Copy link
Contributor

jonhue commented Mar 5, 2021

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 #35584 (comment).

@alexthemark
Copy link

This bug hit my codebase earlier this week.

Would the Typescript team accept a pull request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
3 participants