-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type of element selected from (potentially) empty array #47060
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
Comments
See #39560 |
Thanks, I didn't know about the flag, but as soon as I turned it on I got bombarded with TS errors because the flag deals not only with arrays but also with objects. And I import a lot of objects that aren't typed until I cast them (json, css, ...). Anyway, I still think this report is valid because TS currently doesn't follow JS specification. In JS, if index doesn't exist, it returns |
But the problem is solved. That's exactly what the mentioned flag is for. |
You are right, I guess I just don't agree with the implementation that mixes arrays with objects, but that's another story. Thank you for pointing me to the flag. |
This is equally true of objects? Anyway. |
Bug Report
π Search Terms
array index element undefined
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
firstElement
is of typestring
.π Expected behavior
firstElement
should be of typestring | undefined
orundefined
if that can be deduced.The text was updated successfully, but these errors were encountered: