Typescript: What is the correct type for a Timeout?

In a Web Browser app, setTimeout returns a number.

This setup requires the DOM library (or equivalent).

enter image description here

In a NodeJS app, setTimeout returns a NodeJS.Timeout.

npm install @types/node --save-dev`. 

enter image description here


For this case, I will give you 2 options:

  1. Define type of debounceResize as return type of setTimeout, use ReturnType native generic.
let debounceResize: ReturnType<typeof setTimeout>;
  1. Use window.setTimeout instead of only setTimeout. window.setTimeout returns a number.
let debounceResize: number;

debounceResize = window.setTimeout(() => {}, 1000);