let myTuple:[ string, number ] = [ "hello", 20 ];
// Declare a tuple type
let x: [string, number];
// Initialize it
x = ["hello", 10]; // OK
// Initialize it incorrectly
x = [10, "hello"]; // Error
Type 'number' is not assignable to type 'string'.Type 'string' is not assignable to type 'number'.23222322Type 'number' is not assignable to type 'string'.Type 'string' is not assignable to type 'number'.Try
let yourTuple: readonly [number, number];
yourTuple = [12, 44];
let bgColor, headerColor: [number, number, number, number?];
bgColor = [0, 255, 255, 0.5];
headerColor = [0, 255, 255];
Code language: JavaScript (javascript)