When debugging an arrow function in JavaScript, you can write it like this:
const sum = (a, b) => console.log(a, b) || a + b;
This code will first log a
and b
to the console and then return the actual result of the function. However, when using TypeScript, an error may occur stating that console.log cannot be tested for truthiness:
An expression of type 'void' cannot be tested for truthiness
While this error seems valid, this method is a handy trick for debugging arrow functions, and I would prefer not having to add curly braces to every arrow function if possible.
Even though the console log is temporary, is there any way to make TypeScript accept this pattern without using @ts-ignore
?