@jagapathi Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
In short: it's type-safe, since even if a void returning function is assigned a non-void function, you won't be able to use the result anyway. There is no break in the interface, nor any unintended side effects from not consuming the result.
Also, there is really no benefit from having a compilation error here. Can you think of anything that would be a real problem when you use this code? console.log(square(2)); won't actually compile, so that's not a real situation already.
Hmm, actually compiles. To be honest, not sure why. But also doesn't have any impact at runtime. At most, you'd get a 4 instead of the undefined you expected but...also, if you're logging the result of a void function - why?
@VLAZ well, IIRC, void type is considered by the team as "I do not care about the return type whatsoever". It will compile - I'll try to dig up the issue, folks definitely asked about it before, and the response was that it is by design
I mean, I guess it's because console.log() accepts any and void is assignable. I expected it to be a compilation error but also I can see why it's not. In a properly typed application, that wouldn't really matters, as you wouldn't have any accepting things anyway.
The "not sure" was a shorthand for "I'm too lazy to explain it right now".
@VLAZ yup, and given that console.log is supposed to be able to log undefined, null, etc, it's totally fine that the signature is defined with ...any[] (although it would be great if it was ...unknown[], but it's just a legacy issue)
@OlegValteriswithUkraine oh, nvm about digging up the issue, the FAQ is already linked