strictNullCheck should detect unreachable default values and code after nullish operator #43040
Open
5 tasks done
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Suggestion
Using
strictNullCheck
should allow detection of code that isn't supposed to be reached according to type analysisπ Search Terms
strictNullCheck unreachble nullish default value
β Viability Checklist
My suggestion meets these guidelines:
Yes, especially "Statically identify constructs that are likely to be errors."
β Suggestion
This assumes that it is desired to detect errors with unreachable code due to type analysis (see microsoft/TypeScript-Website#1604 ).
With
strictNullCheck
turned on, some code that is meant to be unreachable and thus an error is not flagged.π Motivating Example
The
= 42
below is unreachable (playground) and is the sign that some code is likely to be an error, but nothing is flaggedEither the declaration should be changed to
x?: number
, or the default should be removed.Another example (thanks to @jcalz) using the nullish operator.
Again, it would be helpful if an error or a warning would be raised as that code seems clearly to be a mistake.
The text was updated successfully, but these errors were encountered: