All files Array.ts

100% Statements 3/3
80% Branches 8/10
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27        1x               9x         11x                  
// https://stackoverflow.com/a/51399781/294171
export type ArrayElement<ArrayType extends readonly unknown[]> =
  ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
 
export function isEntries<
  K extends string | number | symbol = string | number | symbol,
  V = unknown
>(
  obj: unknown,
  isK?: (k: unknown) => k is K,
  isV?: (v: unknown) => v is V
): obj is [K, V][] {
  return (
    Array.isArray(obj) &&
    (obj.length === 0 ||
      obj.reduce(
        (entries, elt) =>
          entries &&
          Array.isArray(elt) &&
          elt.length == 2 &&
          (!isK || isK(elt[0])) &&
          (!isV || isV(elt[1])),
        true
      ))
  );
}