Dev Helpers
← Back

Create typed threshold buckets

Create typed threshold buckets using TypeScript.

Open this example in the interactive library

Source code

type Sample = { time: number; value: number };
const samples: Sample[] = [
  { time: 1, value: 2 },
  { time: 2, value: 6 },
  { time: 4, value: 10 },
];
console.log(samples.map((s): "low" | "high" => (s.value < 5 ? "low" : "high")));

Sample output

[ 'low', 'high', 'high' ]