From bc92c0dfa735a877c166ec263aced65f0162086e Mon Sep 17 00:00:00 2001 From: Changhyun Kim Date: Tue, 21 Jul 2026 17:52:41 +0900 Subject: [PATCH 1/2] fix(types): export MetricObjectWithValues, MetricValue and related types `Registry.getMetricsAsJSON()` returns `MetricObjectWithValues>[]`, and the per-metric `get()` methods return `MetricObjectWithValues<...>`, but those types (along with the base `MetricObject` and `MetricValueWithName`) were not exported. Consumers could not name the return type without resorting to `Awaited>` workarounds. Export them, consistent with the ~20 other public types already exported from this declaration file. Signed-off-by: Changhyun Kim --- index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8c0ebb2c..8c45dae3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -279,7 +279,7 @@ export enum MetricType { type CollectFunction = (this: T) => void | Promise; -interface MetricObject { +export interface MetricObject { name: string; help: string; type: MetricType; @@ -287,18 +287,18 @@ interface MetricObject { collect: CollectFunction; } -interface MetricObjectWithValues< +export interface MetricObjectWithValues< T extends MetricValue, > extends MetricObject { values: T[]; } -type MetricValue = { +export type MetricValue = { value: number; labels: LabelValues; }; -type MetricValueWithName = MetricValue & { +export type MetricValueWithName = MetricValue & { metricName?: string; }; From ad6d736e00135ecfcf8232ab7884e6aad7eba145 Mon Sep 17 00:00:00 2001 From: Changhyun Kim Date: Wed, 22 Jul 2026 10:05:13 +0900 Subject: [PATCH 2/2] test(types): exercise exported metric-object types in typescript test Signed-off-by: Changhyun Kim --- test/typescript.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/typescript.ts b/test/typescript.ts index 80d899ce..36900684 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -12,7 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Counter, Pushgateway, Registry } from '../index'; +import { + Counter, + Pushgateway, + Registry, + MetricObject, + MetricObjectWithValues, + MetricValue, + MetricValueWithName, +} from '../index'; const registry = new Registry(); const counter = new Counter({ @@ -38,3 +46,28 @@ void metricsText; void gatewayWithRegistry; void gatewayWithOptionsAndRegistry; void gatewayWithNullOptionsAndRegistry; + +// The metric-object types are exported, so consumers can name the return +// types of Registry#getMetricsAsJSON()/getMetricsAsArray() and Metric#get() +// instead of re-deriving them. These annotations fail to compile if the types +// are removed, renamed, or reshaped. +async function metricObjectTypesAreExported() { + const asJson: MetricObjectWithValues>[] = + await registry.getMetricsAsJSON(); + void asJson; + + const asArray: MetricObject[] = registry.getMetricsAsArray(); + void asArray; + + const counterSnapshot: MetricObjectWithValues> = + await counter.get(); + void counterSnapshot; + + const named: MetricValueWithName = { + value: 1, + labels: {}, + metricName: 'typescript_test_counter', + }; + void named; +} +void metricObjectTypesAreExported;