Skip to content

Commit 75b63da

Browse files
authored
refactor: make impossible metric types impossible (#768)
1 parent 1f069ae commit 75b63da

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/impact-metrics/metric-types.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Context } from '../context';
22

3-
type MetricType = 'counter' | 'gauge' | 'histogram';
43
type LabelValuesKey = string;
54

65
function getLabelKey(labels?: MetricLabels): LabelValuesKey {
@@ -41,12 +40,19 @@ const isNumericMetricSample = (sample: MetricSample): sample is NumericMetricSam
4140
const isBucketMetricSample = (sample: MetricSample): sample is BucketMetricSample =>
4241
'buckets' in sample;
4342

44-
export interface CollectedMetric {
45-
name: string;
46-
help: string;
47-
type: MetricType;
48-
samples: MetricSample[];
49-
}
43+
export type CollectedMetric =
44+
| {
45+
name: string;
46+
help: string;
47+
type: 'counter' | 'gauge';
48+
samples: NumericMetricSample[];
49+
}
50+
| {
51+
name: string;
52+
help: string;
53+
type: 'histogram';
54+
samples: BucketMetricSample[];
55+
};
5056

5157
interface CollectibleMetric {
5258
collect(): CollectedMetric;

0 commit comments

Comments
 (0)