2 ms·
Yes there is, you can either use as const or define the type as a tuple: const x = [1,2] as const; //const x: [number, number] = [1,2]; const y = x
by tmkn13 7y ago
Yes there is, you can either use as const or define the type as a tuple:
const x = [1,2] as const;
//const x: [number, number] = [1,2];
const y = x[666];//Tuple type 'readonly [1, 2]' of length '2' has no element at index '666'.
const z = y + 3;//Object is possibly 'undefined'.
Both versions will error the same.