There is a (hacky) way of doing that. It's basically adding a new optional element, which is the impossible type never, to the inner array interface. However, that doesn't work if the third element is undefined.
The code below is with the latest Typescript v4.3.2:
TS playground link
interface ArraySizeOfTwo {
0: number;
1: number;
2?: never;
}
interface ArrayList {
[index: number]: ArraySizeOfTwo;
}
const myArray: ArrayList = [
[1, 2],
[15, 20],
];
// Error: Type 'number' is not assignable to type 'undefined'.
const myArray2: ArrayList = [
[1, 2, 3],
[15, 20],
];
// Error: Property '1' is missing in type '[number]' but required in type 'ArraySizeOfTwo'.
const myArray3: ArrayList = [
[1, 2],
[15],
];
// Error: Type 'undefined' is not assignable to type 'number'.
const myArray4: ArrayList = [
[1, 2],
[15, undefined],
];
// no errors :(
const myArray5: ArrayList = [
[1, 2],
[15, 20, undefined],
];
let a: number[2] = [ 0, 1 ]