Skip to content

Add utility to make sure two arrays are the same length/type #1

@crutchcorn

Description

@crutchcorn
type TwoDimentionalArr<T> = T extends ReadonlyArray<infer Q>
  ? Q extends ReadonlyArray<infer I>
    ? ReadonlyArray<ReadonlyArray<I> & { length: Q['length'] }>
    : never
  : never;

type TwoDimentionalNumberArr = TwoDimentionalArr<[number, number][]>;

// Error
const b: TwoDimentionalNumberArr = [[1, 2] as const, [3] as const];
// No error
const c: TwoDimentionalNumberArr = [[1, 2] as const, [3, 4] as const];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions