just read the document ts when I saw that the tuple was out of bounds, I tried the following
let x: [string, number];
x = ["hello", 10];
:
x[3] = "world"; // OK, (string | number)
console.log(x[5].toString()); // OK, "string" "number" toString
x[6] = true; // Error, (string | number)
will report an error here, indicating that the third index value of an array of length 2 cannot be changed directly. Try the push method of another tutorial , and find that it can be inserted successfully, but still cannot be accessed through the index, nor can you change the tuple length property
.I feel a little confused. Ts is a js superset. I feel that I can"t change the array element directly. After push, the element has been inserted but cannot be accessed. What"s going on? ask for advice
.