Index Access Settings
Here we have an array of numbers 1, 2, and 3 in order with the first element at index 0, the second element at index 1, and the third element at index 2.
const array = [1, 2, 3];
We also have a constant mightNotExist
, which attempts to access the third index of the array
. However,
Transcript
00:00 In this exercise, we have an array of numbers here and it's 1, 2, and 3. This 1 is at index 0, this 2 is at index 1, this 3 is at index 2. And we have a const here called might not exist, which is accessing array 3. We know that array 3 actually doesn't exist, curiously.
00:18 And so really, you should expect this because this array is mutable, right? We could add things to it, we could say push, whatever, and now it does exist. And so it might not exist. And so you would expect this type to be number or undefined. But actually, it's being inferred as number.
00:34 Now, this is actually a tsconfig option that we can set true or false. Your job is to figure out which one it is and set it to true. And this is one of the strictness settings. I'll add a link below if you get really stuck. And yeah, enjoy.