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
Change it to use comma operator:
const logger = (...args) => (console.log(args), args);
See the discussion about this change: #26262.
@RyanCavanaugh or @DanielRosenwasser, probably you should add Use of 'void' in control flow constructs is now disallowed to the breaking changes wiki page.
closed as duplicate
Most helpful comment
Change it to use comma operator:
See the discussion about this change: #26262.