```ts
export function kthDistinct(values: number[], k: number): number {
  if (k <= 0 || !Number.isInteger(k)) {
    throw new Error('Invalid rank');
  }

  const distinctValues = Array.from(new Set(values)).sort((a, b) => a - b);

  if (k > distinctValues.length) {
    throw new Error('Rank exceeds the count of distinct values');
  }

  return distinctValues[k - 1];
}
```