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
With strictNullChecks enabled, TypeScript does not include undefined in index signatures (e.g. on an object or array). This is a well known caveat and discussed in several issues, namely #9235, #13161, #12287, and #7140 (comment).
Example:
constxs: number[]=[1,2,3];xs[100]// number, even with strictNullChecks
However, it appears from reading the above issues that many TypeScript users wish this wasn't the case. Granted, if index signatures did include undefined, code will likely require much more guarding, butβfor someβthis is an acceptable trade off for increased type safety.
Example of index signatures including undefined:
constxs: number[]=[1,2,3];xs[100]// number | undefined
I would like to know whether this behaviour could be considered as an extra compiler option on top of strictNullChecks. This way, we are able to satisfy all groups of users: those who want strict null checks with or without undefined in their index signatures.
svieira, felixfbecker, blakeembrey, DanTup, shlomiborovitz and 541 morevivainio, artptr, ycmjason, brainkim, eczn and 6 moreshian15810, aryzing, kirillgroshkov, ycmjason, ericbf and 13 moreagudeluca and Tom-Bonnikeremojansen, antonmedv, arnauorriols, timm-aym, yannick-cw and 90 moreyxliang01, tomconroy, austin-payne, hipstersmoothie, RamonBalthazar and 34 morebrainkim, kirillgroshkov, Onheiron, Titozzz, agudeluca and 3 more