Skip to content

Function truthy check doesn't apply if the function is in a boolean expression #37598

Closed
@afrieder

Description

@afrieder

TypeScript Version: 3.8.2, nightly

Search Terms:
Function truthiness, function truthy check

Code

const someBool = true;

function f() {}

if (f) {}

if (someBool && f) {}

if (!someBool || f) {}

Expected behavior:
All three if statements should throw a This condition will always return true since the function is always defined. Did you mean to call it instead? error.

Actual behavior:
Only the first statement throws the error.

Playground Link: https://www.typescriptlang.org/play/index.html?ts=Nightly#code/MYewdgzgLgBBIFsCmAhEIA2MC8MoCcBXJAbgFgAoSgM0LGCgEtwZqAKAShgG8BfSyo2ow21LnwEUhI+MjSYYAMkWtx-KlOFsAhLNTosAH0OqevIA

Related Issues:
#37149

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions