Type alias ArrayTranspose<M, N>

ArrayTranspose<M, N>: M extends EmptyArray
    ? EmptyArray
    : {
        [KN in Keys<N>]: {
            [KM in Keys<M>]: KN extends Keys<M[KM]>
                ? M[KM][KN]
                : never
        }
    }

Transposes a given 2xN array or matrix M, flipping the matrix over its diagonal, switching its row and column indices.

Type Parameters

Example

// Transpose a 1x1 matrix
type Matrix = ArrayTranspose<[[1]]>; // expected to be [[1]]

Example

// Transpose a 2x2 matrix
type Matrix1 = ArrayTranspose<[[1, 'i'], [3, 4]]>; // expected to be [[1, 3], ["i", 4]]

Example

// Transpose a 2x3 matrix
type Matrix2 = ArrayTranspose<[[1, true, 3], [4, 5, 6]]>; // expected to be [[1, 4], [true, 5], [3, 6]]