Skip to content

error TS1345: An expression of type 'void' cannot be tested for truthiness - console.log(x) || x #28248

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

Closed
rolandpeelen opened this issue Oct 31, 2018 · 3 comments

Comments

@rolandpeelen
Copy link

In a functional context, I often use loggers like this;

const logger = (...args) => console.log(args) || args;

As console.log() returns undefined, it will always fall through the next argument. However, my angular project now no longer compiles.

-->

TypeScript Version: 3.1.4

Search Terms:
error TS1345: An expression of type 'void' cannot be tested for truthiness
found some issues, but not the same.
Code

const logger = (...args) => console.log(args) || args;

Expected behavior:
Compile

Actual behavior:
gives error

@j-oliveras
Copy link
Contributor

Change it to use comma operator:

const logger = (...args) => (console.log(args), args);

See the discussion about this change: #26262.

@j-oliveras
Copy link
Contributor

@RyanCavanaugh or @DanielRosenwasser, probably you should add Use of 'void' in control flow constructs is now disallowed to the breaking changes wiki page.

@rolandpeelen
Copy link
Author

closed as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants