Try   HackMD

Typescript - Generic Object Types

https://www.typescriptlang.org/docs/handbook/2/objects.html

interface ArrayType<Type> {
  length: number;
  slice(start: number, end: number): Type;
}


function getShuffledArray<Type extends ArrayType<Type>>(array: Type): Type {
  for (let i = array.length - 1; i > 0; i -= 1) {
    const j = Math.floor(Math.random() * (i + 1));
    const temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
  return array;
}

function getArrayPart<Type extends ArrayType<Type>>(array: Type, startIndex: number, endIndex: number): Type {
  if (endIndex > array.length) {
    return array.slice(startIndex, array.length);
  }
  return array.slice(startIndex, endIndex);
}

tags: typescript generics