Ask questionsrefine type of array access to non-undefined given proper for-loop header

Maybe Hegel could check loop headers, and if the iteration variables are written properly, then it can narrow the types of array access to non-undefined.

For example, in the code

let nums: Array<number> = [0,1,2,3]

for (let i=0; i<nums.length; i++) {
  const n = nums[i] // must be a number

it will not go out of bounds, so there is no check needed like n != undefined && useNum(n).

Sorry for opening so many issues! There are lots of ideas. :)


Answer questions vkurchatkin

There is no way to avoid this check, unless we go into the realm of dependent types


Related questions

No questions were found.
Github User Rank List