You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code can be unreachable because of javascript itself, or because of type annotations (but potentially reachable at runtime).
The documentation for allowUnreachableCode states that it affect the former but that it "does not affect errors on the basis of code which appears to be unreachable due to type analysis".
This seems to be inaccurate since ~3.7 that introduced never:
In both of these examples, it is possible to reach this code at runtime if using javascript code that does not respect the type annotations. The allowUnreachableCode config affects the error reporting.
The documentation does not state what is the expected behavior of code unreachable due to type annotations.
It is very useful to detect unreachable code (of either kind) as these are almost always due to errors in the code. I hope that typescript will be able in the future to report more of these cases (I am opening for this; other example is Detect unreachable code in more scenarios TypeScript#39995).
These errors could either be grouped together, or else a new kind of error (with a corresponding config flag) should be created. In all cases documentation should describe the current state of affairs.
The text was updated successfully, but these errors were encountered:
I think the docs just need to be fixed. We assume you're not trying to intentionally bungle your types and lie, otherwise this sort of warning isn't as useful.
Hello! As per #2804, we are automatically closing all open issues. Please see #2804 for a description of what issues and PRs can be accepted going forward.
Suggestion
Clarify official position on unreachable code due to static typing.
🔍 Search Terms
unreachable code allowUnreachableCode 7027
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Code can be unreachable because of javascript itself, or because of type annotations (but potentially reachable at runtime).
The documentation for
allowUnreachableCode
states that it affect the former but that it "does not affect errors on the basis of code which appears to be unreachable due to type analysis".never
:Here's an example with an implicit
never
from microsoft/TypeScript#39386:An example with an explicit
never
from microsoft/TypeScript#34879:In both of these examples, it is possible to reach this code at runtime if using javascript code that does not respect the type annotations. The
allowUnreachableCode
config affects the error reporting.The documentation does not state what is the expected behavior of code unreachable due to type annotations.
It is very useful to detect unreachable code (of either kind) as these are almost always due to errors in the code. I hope that typescript will be able in the future to report more of these cases (I am opening for this; other example is Detect unreachable code in more scenarios TypeScript#39995).
These errors could either be grouped together, or else a new kind of error (with a corresponding config flag) should be created. In all cases documentation should describe the current state of affairs.
The text was updated successfully, but these errors were encountered: