Modifying a Tuple in TypeScript
The elements of a tuple can be modified by writing values of the appropriate type into them. Let's look at an example. Let's say we have the following tuple:
let user: [string, number] = ['john', 31];
Let's change its element:
user[0] = 'eric';
console.log(user);
But an attempt to write a value of a different type into a tuple element will result in an error:
user[0] = 12; //
Tell me what the result of running the following code will be:
let time: [number, number, number] = [12, 59, 59];
time[0] = 13;
console.log(time);
Tell me what the result of running the following code will be:
let time: [number, number, number] = [12, 59, 59];
time[0] = '01';
console.log(time);