Using typescript 4.1.2 with strict: true, I can declare a function like this without any complaints from the compiler:
function someFunction(): void {
throw Error(`y so salty?`);
}
In my understanding, this function should be typed as returning never. I am quite surprised the compiler does not complain about void here.
After all, it makes a huge difference when calling the function. Anything after a never-returning function call will be unreachable code, which is not the case for void. I'd certainly like to know about that difference.
- What's the reason for TS being so lax here?
- Can I prevent this kind of behavior via the TS config?
- (bonus) is there – or could there even be – an
eslintrule to cover this?