1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import { Counter , Pushgateway , Registry } from '../index' ;
15+ import {
16+ Counter ,
17+ Pushgateway ,
18+ Registry ,
19+ MetricObject ,
20+ MetricObjectWithValues ,
21+ MetricValue ,
22+ MetricValueWithName ,
23+ } from '../index' ;
1624
1725const registry = new Registry ( ) ;
1826const counter = new Counter ( {
@@ -38,3 +46,28 @@ void metricsText;
3846void gatewayWithRegistry ;
3947void gatewayWithOptionsAndRegistry ;
4048void gatewayWithNullOptionsAndRegistry ;
49+
50+ // The metric-object types are exported, so consumers can name the return
51+ // types of Registry#getMetricsAsJSON()/getMetricsAsArray() and Metric#get()
52+ // instead of re-deriving them. These annotations fail to compile if the types
53+ // are removed, renamed, or reshaped.
54+ async function metricObjectTypesAreExported ( ) {
55+ const asJson : MetricObjectWithValues < MetricValue < string > > [ ] =
56+ await registry . getMetricsAsJSON ( ) ;
57+ void asJson ;
58+
59+ const asArray : MetricObject [ ] = registry . getMetricsAsArray ( ) ;
60+ void asArray ;
61+
62+ const counterSnapshot : MetricObjectWithValues < MetricValue < string > > =
63+ await counter . get ( ) ;
64+ void counterSnapshot ;
65+
66+ const named : MetricValueWithName < string > = {
67+ value : 1 ,
68+ labels : { } ,
69+ metricName : 'typescript_test_counter' ,
70+ } ;
71+ void named ;
72+ }
73+ void metricObjectTypesAreExported ;
0 commit comments