Today I Learned

[TS] Get return type of any function

February 01, 2022

Sometimes it’s quite tricky to assign a type to a variable, for example in the case when the interval variable has different types based on the environment the app’s running (Node or a browser) so there is no correct type for this interval variable.

Using ReturnType<typeof …> can resolve it:

let interval: ReturnType<typeof setInterval>;

interval = setInterval(...);

© 2025 - Written by Vuong Vu. Connect with me on LinkedIn.