You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript: LabelValues distributes over label-name unions, so labels from get() lose all but one key #861
Because T is a naked type parameter, TypeScript distributes the conditional over each member of a label-name union. For a metric with labelNames: ['a', 'b'], LabelValues<'a' | 'b'> becomes Partial<Record<'a', string | number>> | Partial<Record<'b', string | number>> rather than a single object with both keys.
Writes still compile, but reading labels back does not, e.g. from get():
import{Counter}from'@prometheus-io/client';constc=newCounter({name: 'x_total',help: 'x',labelNames: ['a','b']asconst});c.inc({a: '1',b: '2'});const{ values }=awaitc.get();values[0].labels.a;// error TS2339: Property 'a' does not exist on type// 'Partial<Record<"a", string | number>> | Partial<Record<"b", string | number>>'.
This compiled with prom-client 15.1.3, where LabelValues<T> was Partial<Record<T, string | number>>.
Wrapping both sides in a tuple disables distribution and keeps the never (no labels) case working:
(As a side effect, the current form also resolves to never rather than Partial<Record<string, never>> when T is never, since a distributive conditional over never yields never.)
Activity