When using valid debugging code like the example below, TypeScript may throw an error ("An expression of type 'void' cannot be tested for truthiness.ts(1345)"):
const getFooPlusTwo = (foo) => console.log(foo) || foo + 2;
There are various hacks that can be used to work around this issue, such as adding +
, ,
, etc. However, these workarounds may not be effective in all circumstances and can add unnecessary complexity without any real benefit, as JavaScript functions fine without them.
Fortunately, most TypeScript rules can be disabled. Are there any TypeScript (or ESLint) rules that I can turn off to prevent TypeScript from throwing these errors?