Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram startTimer return value in typescript definition incorrect? #617

Open
kevkcc opened this issue Mar 2, 2024 · 1 comment
Open

Comments

@kevkcc
Copy link

kevkcc commented Mar 2, 2024

Hi,

I was wondering if the following line should return number instead of void.

startTimer(): (labels?: LabelValues<T>) => void;

I wanted to start a timer on a specific label and am doing something like this in my code:

const end = histogram.labels({ mylabels }).startTimer();
// some stuff
const seconds = end();

But I was surprised to see that this startTimer in the ts definitions doesn't return number and supposedly returns void. In testing, my code works and it still returns a number so I believe it's just a problem with the ts definition.

@a1300
Copy link

a1300 commented Oct 16, 2024

Looks like this has been fixed in index.d.ts:

prom-client/index.d.ts

Lines 504 to 511 in c1d76c5

/**
* Start a timer. Calling the returned function will observe the duration in
* seconds in the histogram.
* @param labels Object with label keys and values
* @return Function to invoke when timer should be stopped. The value it
* returns is the timed duration.
*/
startTimer(labels?: LabelValues<T>): (labels?: LabelValues<T>) => number;

@siimon this issue can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants