Bug Report
π Search Terms
- noUncheckedIndexedAccess
- for...of
π Version & Regression Information
- typescript@4.1.2
- typescript@4.2.0-dev.20210203
β― Playground Link
Playground Link
π» Code
// this example requires "noUncheckedIndexedAccess" to be enabled to make sensefunctionsomeNumberFunction(_: number){}constmyArray: number[]=[]myArray[5]=5for(leti=0;i<myArray.length;++i){constv=myArray[i]// v is "number | undefined"...if(v!=null){// ... so it needs to be checked for undefinedsomeNumberFunction(v)}}for(constvofmyArray){// v is "number" according to TypeScript...// ... so we can erroneously call the function without checking for undefinedsomeNumberFunction(v)}π Actual behavior
With noUncheckedIndexedAccess enabled, value v in the for...of loop is still treated as number, allowing to unwittingly further process an undefined value.
π Expected behavior
Value v should be treated as number | undefined to be consistent with index access on arrays.
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
With
noUncheckedIndexedAccessenabled, valuevin thefor...ofloop is still treated asnumber, allowing to unwittingly further process anundefinedvalue.π Expected behavior
Value
vshould be treated asnumber | undefinedto be consistent with index access on arrays.