-
Notifications
You must be signed in to change notification settings - Fork 12.8k
| undefined
should be part of type when getting items from an array
#38470
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
Duplicate of #13778. |
Duplicate #13778 |
@MartinJohns easy dupe day eh |
@RyanCavanaugh I spend way too much time reading these issues in this repository, for quite some time already (using TypeScript since preview version), so I often recognize repeated issues. Just sometimes I fail to find the original issue. |
@RyanCavanaugh @MartinJohns However I did not see this tuple behavior being address in the other thread.. Can't see how those arguments would apply here: // tuple
var str = '';
var aa = [str, str] as const
var _shouldBeString = aa[0] //string
var _notString1 = aa[10000]; // type error
var _notString2 = aa[Infinity]; // no error, type string
var _notString3 = aa[NaN]; // no error, type string |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Search Terms: Array type
Code
Simplest code:
I get the difficulty in discerning
0
,10
,NaN
andInfinity
since the type of all those isnumber
.. but wouldn't it make sense then to make the return type from these queriesstring | undefined
?For those who don't want that they can turn off
strictNullChecks
Tuples are only slightly better
Expected behavior:
Actual behavior:
Playground Link:
TS-Playground
Related Issues:
The text was updated successfully, but these errors were encountered: