-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some code written in strict mode is invalid in non-strict mode #17774
Comments
Seems like the ergonomics of using |
@DanielRosenwasser what's the concrete change that's supposed to happen? |
This is working as intended. See #11432 and #13779 for context. In particular, note that in I'm perfectly happy to consider alternate proposals, but the currently behavior is a careful balance of performing better analysis when we can in |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.4.0
Code
Consider the following snippet:
Typescript infers
EMPTY_ARRAY
to beany[]
and doesn't complain even withnoImplicitAny
turned on. Things get weirder, when we start using this variable:We get no implicit any error in 2 places. A questionable attempt at fixing this might be to type
EMPTY_ARRAY
asnever[]
orReadonlyArray<never>
which results in no errors:Questionability of this 'fix' aside, one would expect that turning off
strictNullChecks
would result in the code continuing to compile, but it's not the case:Expected behavior:
Not sure how this should be fixed tbh. To me it seems like
never[]
is not a type that should be allowed in either mode, since mutating the array will certainly break this.ReadonlyArray<never>
looks like a valid option. On top of this, I'd expect that making the compiler less strict will keep the strict code compiling.Actual behavior:
Described above.
The text was updated successfully, but these errors were encountered: