Summary
Nested array destructuring of a literal whose elements have different types is rejected by the type checker, in both declaration and assignment (#754) forms:
const [[m], n] = [[7], 8]; // Type Error: Index type '0' is not valid for indexing all members of union type 'number[] | number'.
let m2, n2; [[m2], n2] = [[7], 8]; // same
Uniform nesting works: const [[m], [k]] = [[7], [8]] (element type number[]). An explicit tuple annotation does not help (const [[m], n]: [number[], number] = [[7], 8] fails the same way).
Cause
[[7], 8] is inferred as (number[] | number)[] (array, union element) rather than the tuple [number[], number]. The __arrayDestructure normalization (#685) passes arrays through and indexes positionally, so src[0] is the union number[] | number, which is not indexable for the nested [m]. tsc uses the binding pattern as contextual type to infer the rhs as a tuple.
Fix shape
Propagate the destructuring pattern's arity/shape as a contextual type to the initializer so a mixed array literal infers as a tuple (SharpTS already has TryCheckArrayLiteralAsTuple for tuple-context inference — it just is not threaded through __arrayDestructure source checking). Pre-existing; surfaced again by #754.
Summary
Nested array destructuring of a literal whose elements have different types is rejected by the type checker, in both declaration and assignment (#754) forms:
Uniform nesting works:
const [[m], [k]] = [[7], [8]](element typenumber[]). An explicit tuple annotation does not help (const [[m], n]: [number[], number] = [[7], 8]fails the same way).Cause
[[7], 8]is inferred as(number[] | number)[](array, union element) rather than the tuple[number[], number]. The__arrayDestructurenormalization (#685) passes arrays through and indexes positionally, sosrc[0]is the unionnumber[] | number, which is not indexable for the nested[m]. tsc uses the binding pattern as contextual type to infer the rhs as a tuple.Fix shape
Propagate the destructuring pattern's arity/shape as a contextual type to the initializer so a mixed array literal infers as a tuple (SharpTS already has
TryCheckArrayLiteralAsTuplefor tuple-context inference — it just is not threaded through__arrayDestructuresource checking). Pre-existing; surfaced again by #754.