ts-reset icon indicating copy to clipboard operation
ts-reset copied to clipboard

Feature request: Fix or ignore control flow type narrowing errors in unreachable code

Open philipaarseth opened this issue 2 years ago • 0 comments

One annoying behaviour with typescript is that control flow type narrowing does not work in unreachable code. Even if the code is unreachable, the compiler will still complain on all the type errors within the unreachable code. Not talking about the unreachable code warning, which is very helpful.

Right now you have to comment out the entire unreachable code block (or try to make a debugger play nice in your environment), which works but seeing the goal of the project is fixing annoying typescript behaviour, I feel like this fits.

Here's the TS bug issue, it was made in 2018 so I'm not holding my breath that there will be progress any time soon. https://github.com/microsoft/TypeScript/issues/26914

Fixing it is probably not worth, seeing as typescript already warns you that you have unreachable code, having errors inside your warning seems superfluous.

So what I'm suggesting is either A) ignoring them altogether or B) converting the errors to warnings inside the unreachable code block.

That way you don't have to comment out everything below the return any time you want to ensure that part of your function executes correctly.

philipaarseth avatar Feb 23 '23 17:02 philipaarseth